Skip to content

4. Conversion to native values

The rules of this section apply to each value whose subschema has estype, directly or through $ref (CONVERT_REF). A converter is an implementation at the Converter level (section 5.1).

CONVERT_PLAIN_SHOULD SHOULD

A library that deserializes plain JSON with a schema, and does not claim the Converter level, SHOULD convert each value whose subschema has estype from its plain JSON form to the native value of that ES type.

CONVERT_ACCEPTED_FORMS MUST

A converter MUST accept, for each ES type, a value without a tag in its plain JSON form (ECSON section 5.3) and a value without a tag in the serialized form that ECSON writes inside the tag. For example, a bigint is accepted as 42 and as "42", and a date as "2024-01-15T00:00:00.000Z" and as 1705276800000.

CONVERT_PLAIN_READ MUST

A converter MUST read a value without a tag by mapping it to the serialized form of the tag of its ES type, as the inverse of the plain JSON form of ECSON section 5.3 (a value already in the serialized form stays as it is), and by deserializing that form by the rules of ECSON. A form that ECSON rejects fails CONVERT_FAIL.

CONVERT_PLAIN_LOSS MUST

A converter MUST read the plain JSON form of a symbol (a string) as a new symbol with that description, which is not in the global symbol registry; the plain JSON form of bytes (a Base64 string) as a Uint8Array; and the plain JSON form of binary (a Base64 string) with the subtype 00.

CONVERT_NULL MUST

A plain JSON null MUST NOT be converted: it stays null, and is valid only when the declared schema accepts it. This does not apply to a null inside a tag, such as { "$date": null } (an invalid date) or { "$rel": null } (an empty reference), which is converted.

CONVERT_NESTED MUST

Subschemas nested in the declared schema MUST be applied to the members of the value after conversion, whether the value arrived in the ECSON form or in the plain JSON form. The declared schema sees a set as the array of its members and a map as the array of its [key, value] pairs, as in their plain JSON forms, so items (and, for a map, prefixItems inside items) describes the members in both forms.

CONVERT_ECSON_WITH_SCHEMA MUST

A converter MUST, when deserializing with a schema, produce the native value of each value whose subschema has estype, whether the value is in the ECSON form or in the plain JSON form.

CONVERT_REF MUST

A value whose subschema reaches a subschema with estype through $ref MUST be converted as for that subschema. A $ref to an entry of the definitions document follows DEFS_EQUIVALENT.

CONVERT_FAIL MUST

A value whose subschema has estype T, that is not in the ECSON form of T and cannot be converted to T, MUST be reported as not valid against the schema, with the path of the value.

CONVERT_PATH_POINTER SHOULD

The path of a value in a report of CONVERT_FAIL or CONVERT_MALFORMED_ECSON SHOULD be a JSON Pointer (RFC 6901).

CONVERT_FORM_PER_FIELD MUST

A converter MUST determine the form of each value (ECSON form or plain JSON form) independently of the other values of the document.

CONVERT_MALFORMED_ECSON MUST

A value in the ECSON form of its ES type whose serialized form is malformed MUST be reported as not valid against the schema, as a failure of the ECSON rule TYPEDEF_VALIDATE, with the path of the value.

CONVERT_MALFORMED_DETAIL MAY

A converter MAY add the path inside the serialized form to the report of CONVERT_MALFORMED_ECSON, as extra information.

Source: lingodata/estype@0cbfb46 · spec/sections/04-conversion.md · estype 0.1.0 (draft)

LingoData specifications, reference implementations and this site are licensed under the Apache License 2.0. Copyright 2026 Gustavo Gondim.