JSON schema to C and C++ mapping
The DFHJS2LS utility programs support mappings between the JSON schemas and C and C++ data types.
- Characters other than A-Z, a-z, 0-9, or _ are replaced with
'
X'.For example,
monthly-totalbecomesmonthlyXtotal. - If the first character is not an alphabetic character, it is replaced by a
leading '
X'.For example,
_monthlysummarybecomesXmonthlysummary. - Duplicate names in the same scope are made unique by the addition of one or two
numeric digits to the second and subsequent instances of the name.
For example, three instances of
yearbecomeyear,year1, andyear2. - A JSON schema specifies that a variable has varying cardinality if it has a
"type"value of"array", and the keywords"minItems"and"maxItems"are omitted or have different values. If the schema specifies that the variable has varying cardinality, then field names are created with suffixes of"_cont"and"_num".For more information, see Variable arrays of elements in DFHJS2LS.
- A JSON schema specifies that a variable is optional if it does not appear in the
"required"keyword array that is associated with the enclosing JSON schema"object"type. For optional fields, an additional field is generated with a suffix of_numadded to the element name. At run time this is zero to indicate the value was absent from the JSON data, and non-zero if the value was present in the JSON data. - Field names are limited to 50 characters. If a generated name, including any prefix and suffix, exceeds this length, the element name is truncated.
- If the MAPPING-LEVEL parameter is set to 1.2 or higher and the CHAR-VARYING parameter is set to NULL, variable-length character data is mapped to null-terminated strings and an extra character is allocated for the null-terminator.
- If the MAPPING-LEVEL parameter is set to 1.2 or higher and the CHAR-VARYING parameter is set to YES, variable-length character data is mapped to two related elements: a length field and a data field.
| JSON Schema keyword | C and C++ data type |
|---|---|
All
of: |
Not supported |
|
This keyword is ignored, but it is assumed to be compatible with the draft 04 JSON Schema specification. |
|
These keywords are ignored. |
|
The "format" keyword is used to modify either the generated structure or runtime value. See the following information for the supported use of "format". |
|
The only form of JSON array currently
supported is a repeated number of same type values. The
If both |
|
|
|
The only form of JSON object currently supported is a fixed set of named elements. This will generate a structure (or sub-structure) using the element names.
Any
element in the |
|
None of these keywords are supported with JSON objects. |
|
where the value of z is based on m, but dependent on the settings of the CHAR-VARYING parameter. m is
based on the
|
|
When CCSID=1200 at mapping level 4.0 and higher:
where the value of z is based on m, but dependent on the settings of the CHAR-VARYING parameter. m is based on the |
|
All
supported when |
|
where m is
based on the When CCSID=1200 at mapping level 4.0 and higher:
where m is
based on the |
|
where m is
based on the |
|
where m is
based on the |
|
where m is
based on the When CCSID=1200 at mapping level 4.0 and higher:
where m is
based on the |
|
bool (C++ only)short (C only) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mapping level 1.1 and lower:
Mapping level 1.2 and higher:
Note: The IBM® Hexadecimal Floating Point (HFP)
data representation is not exactly the same as the IEEE-754-1985 representation
used for JSON. Some values may not convert exactly from one representation
to the other. Some extremely large or small values might not be valid
for float data types. Some values may lose precision when converted
to or from HFP representation. If precise conversions are important,
consider replacing use of float data types with fixed precision alternatives.
|
|
Mapping level 1.0 and lower:
Mapping level 1.2 and higher:
Note: The IBM Hexadecimal Floating Point (HFP)
data representation is not exactly the same as the IEEE-754-1985 representation
used for JSON. Some values may not convert exactly from one representation
to the other. Some extremely large or small values might not be valid
for double data types. Some values may lose precision when converted
to or from HFP representation. If precise conversions are important,
consider replacing use of double data types with fixed precision alternatives.
|