json_null attribute

This attribute controls the representation of null or empty values. json.Serializer uses it during both serialization and deserialization, but util.JSON applies it only when serializing.

Syntax

json_null = {"null" | "undefined"}
  1. "null": writes null or empty BDL elements as the JSON null keyword.
  2. "undefined": omits null or empty BDL elements from the JSON output (except for the root element).

Usage

Use json_null="null" to represent null or empty BDL values using the JSON null keyword during serialization. This also enables deserialization of JSON null values into BDL variables.

Use json_null="undefined" to omit null or empty BDL elements from the resulting JSON. The root element is never omitted, and null values inside arrays must still be written as null to preserve index positions. For detailed behavior and examples, go to JSON nulls and empty structures.

When you use json.Serializer, null values are rejected unless you enable the allowNullAsDefault (deserialization) or serializeNullAsDefault (serialization) options, or define variables with json_null="null".

Affects

The behavior of the json_null attribute differs between util.JSON and json.Serializer:

  • util.JSON: The attribute affects serialization (BDL to JSON) only. A missing root value is treated as null, and schema-related attributes such as JSONRequired are ignored at runtime.
  • json.Serializer: The attribute affects both serialization (BDL to JSON) and deserialization (JSON to BDL). A missing root value is considered an error, and schema-related attributes such as JSONRequired are processed, validated, and enforced.

For a full comparison of json_null handling, go to json_null handling differences.

Example

To enable null value handling on individual fields:

TYPE myRecordType RECORD
  id INTEGER,
  name VARCHAR(50) ATTRIBUTES(json_null="null"),
  description VARCHAR(100) ATTRIBUTES(json_null="null")
END RECORD

For more information about null and undefined handling, go to JSON nulls and empty structures.