4. Extension type sets
A type set is a named group of tags with their serialized forms. The core type set (section 3) contains the native JavaScript types. Official extension type sets, defined in this section, cover types from other ecosystems and native types that are not in the core type set, such as errors. Implementations decide how to package each set.
TYPESET_OPTIONAL MAY
An implementation MAY support any official extension type set, in whole. Partial support of a set is not compliant with that set.
4.1 BSON type set
Section titled “4.1 BSON type set”Covers the BSON types used by MongoDB that are not native JavaScript types. Its forms are identical to MongoDB Extended JSON v2, so that ECSON values can be exchanged with MongoDB tools.
BSON_FORMS MUST
The BSON type set MUST use the tags and forms in the table below, which are identical to the canonical format of MongoDB Extended JSON v2.
| BSON type | Form |
|---|---|
| ObjectId | { "$oid": "507f1f77bcf86cd799439011" }: 24 hexadecimal characters, big-endian bytes |
| Binary | { "$binary": { "base64": "c3VyZS4=", "subType": "00" } }: Base64 with padding, subtype as a 1 or 2 digit hexadecimal string |
| Decimal128 | { "$numberDecimal": "9.99" } |
| Timestamp | { "$timestamp": { "t": 1678886400, "i": 1 } }: non-negative integers |
| MinKey | { "$minKey": 1 } |
| MaxKey | { "$maxKey": 1 } |
BSON_HEX_CASE MUST
Writers MUST emit hexadecimal strings ($oid, subType) in lowercase, and readers MUST accept them in any case.
BSON_DECIMAL_EXACT MUST
When deserializing, a $numberDecimal string MUST follow the string syntax of the MongoDB Decimal128 specification (e or E for the exponent; Inf, Infinity and NaN in any case) and MUST represent a Decimal128 exactly: clamping and rounding that do not change the value are allowed, and a string that needs inexact rounding, overflows or underflows MUST fail (TYPEDEF_VALIDATE).
Writers MUST emit the canonical Decimal128 string of the MongoDB Decimal128 specification (for example, 1e3 is written as 1E+3).
A reader that supports the BSON type set MAY also accept the MongoDB canonical date form { "$date": { "$numberLong": "<milliseconds>" } } when deserializing. Writers MUST NOT emit it: dates are always written in the core $date form (section 3.1).
4.2 References type set
Section titled “4.2 References type set”Covers references from one value to another resource: links to anything addressable by a URI, and references to resources in the same data source.
REF_TAG MUST
The References type set MUST use the tag $rel, whose value is one of the forms in the table below, or null for an empty reference: a single reference that points to nothing.
| Form | Value | Example |
|---|---|---|
| URI | a string with a URI (RFC 3986, section 3), either a URL or a URN, with an optional fragment | { "$rel": "urn:isbn:9780262033848" } |
| Link header | a string with the value of an HTTP Link header field (RFC 8288, section 3), with one or more links |
{ "$rel": "<https://api.example.com/users/42>; rel=\"author\", <https://api.example.com/users/7>; rel=\"editor\"" } |
| Link object | an object with an href URI string and, optionally, rel and the target attributes of RFC 9264, section 4.2 (type, title, hreflang and others) |
{ "$rel": { "href": "https://api.example.com/users/42", "rel": "author", "type": "application/vnd.ecson+json", "title": "Ana", "hreflang": ["pt-BR"] } } |
| Collection object | an object with a collection name and either an id or an ids array |
{ "$rel": { "collection": "tags", "ids": ["promo", "delivery"] } } |
| Array | an array of URI strings, link objects and collection objects, for several references | { "$rel": ["https://example.com/a", { "href": "https://example.com/b", "rel": "related" }, { "collection": "products", "id": "p1" }] } |
REF_STRING_FORMS MUST
A string value starting with < MUST be interpreted as a Link header value; any other string MUST be interpreted as a URI (RFC 3986, section 3). A string that is not a URI, such as a relative reference (/users/42) or the empty string, makes the value malformed.
REF_OBJECT_FORMS MUST
An object value with an href member MUST be interpreted as a link object, and an object value with a collection member as a collection object. An object with both, or with neither, is malformed.
REF_ARRAY MUST
An array value MUST contain only URI strings, link objects and collection objects, in any combination; it MUST NOT contain Link header strings, which already represent several links, nor nested arrays.
REF_EMPTY MUST
An empty array value and a collection object with an empty ids array MUST be accepted as zero references: a list that has no references, which is not the same as null, the empty reference of REF_TAG. With an empty ids, data, when present, is an empty array.
REF_COLLECTION_ID MUST
The id of a collection object, and each element of ids, MUST be an ECSON value other than null, $undefined, a boolean, an array or a plain object, such as a string, a number, a $bigint or an $oid. Other values make the collection object malformed.
REF_LINK_ATTRIBUTES MUST
The members of a link object MUST have the JSON types of RFC 9264, section 4.2: href, rel, title, type and media are strings; attributes whose name ends with * are arrays of objects with a value string, an optional language string and no other members; hreflang and the other attributes, including extension attributes, are arrays of strings. Other types make the link object malformed.
A collection object MAY include a data member with a snapshot of the referenced data: an object (or null, when not found) for id, or an array in the same order as ids. The data member is not part of the reference: writers that store references MUST ignore it.
REF_COLLECTION_SAME_SOURCE MUST
A collection object MUST refer to Resources stored in the same data source as the value that contains it. References to anything else MUST use a URI, Link header or link object form.
4.3 Error type set
Section titled “4.3 Error type set”Covers ECMAScript error objects.
ERROR_FORM MUST
An error MUST be serialized under the tag $error as an object with a name string and a message string, and MAY include cause (any ECSON value), errors (an array of ECSON values, for AggregateError and for any other error whose own errors property is an array), stack (a string) and props (an object with the own enumerable properties of the error other than name, message, cause, errors and stack, such as code, serialized as ECSON). Other members MUST fail (TYPEDEF_VALIDATE).
ERROR_NATIVE MUST
When deserializing, an implementation MUST create the native error type named by name when it is one of Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError or AggregateError, and MUST otherwise create an Error whose name is the received name.
ERROR_ERRORS_READ MUST
When deserializing, an error whose name is AggregateError and that has no errors MUST fail (TYPEDEF_VALIDATE). An errors in an error with another name MUST be restored as an own property errors of the created error.
ERROR_STACK_READ MUST
When deserializing, a received stack MUST replace the stack of the created error.
ERROR_PROPS MUST
When deserializing, the members of props MUST be restored as own properties of the error.
ERROR_PROPS_KEYS MUST
A props with the key name, message, cause, errors or stack MUST fail (TYPEDEF_VALIDATE). An empty props is valid.
ERROR_STACK_OPT_IN SHOULD NOT
Implementations SHOULD NOT serialize stack unless the application asks for it.
Source: lingodata/ecson@fe27835 · spec/sections/04-extension-types.md · ecson 0.2.0 (draft)
LingoData specifications, reference implementations and this site are licensed under the Apache License 2.0. Copyright 2026 Gustavo Gondim.