Skip to content

3. Built-in types

Built-in types are the native JavaScript types that every full ECSON implementation supports. They form the core type set. Other types are added through extension type sets (section 4).

Each built-in type has a single serialized form, except where a type explicitly defines alternatives (such as $date). There are no global serialization modes.

Represents a Date object.

TYPE_DATE_STRING SHOULD

A valid date SHOULD be serialized as a string in the RFC 3339 format, in UTC, with millisecond precision and the Z suffix (YYYY-MM-DDTHH:mm:ss.sssZ).

TYPE_DATE_EPOCH MAY

A valid date MAY be serialized as an integer number of milliseconds since the Unix epoch.

TYPE_DATE_EPOCH_RANGE MUST

A valid date whose year is outside the range 0000 to 9999 MUST be serialized as an integer number of milliseconds since the Unix epoch, because RFC 3339 cannot represent it.

TYPE_DATE_READ MUST

When deserializing $date, an implementation MUST accept both the RFC 3339 string form and the integer epoch form.

TYPE_DATE_READ_STRICT MUST

When deserializing $date, the string form MUST follow the date-time production of RFC 3339, section 5.6, with these differences: a leap second (:60) MUST fail, and fractions longer than milliseconds MUST be truncated, not rounded. Any UTC offset is accepted, and t and z are accepted in lowercase. A space instead of T, an epoch that is not an integer, and an epoch outside plus or minus 8.64e15 milliseconds (the ECMAScript time range) MUST fail (TYPEDEF_VALIDATE).

TYPE_DATE_INVALID MUST

An invalid date (a Date whose time value is NaN) MUST be serialized as { "$date": null }, and { "$date": null } MUST be deserialized as an invalid date.

Represents a BigInt value.

TYPE_BIGINT MUST

A BigInt MUST be serialized as a string of decimal digits, with an optional leading -, no leading + and no leading zeros (the value zero is "0").

Represents the IEEE 754 values that JSON cannot express.

TYPE_NUMBER_SPECIAL MUST

The number values NaN, Infinity, -Infinity and negative zero MUST be serialized as { "$number": "NaN" }, { "$number": "Infinity" }, { "$number": "-Infinity" } and { "$number": "-0" }, respectively.

TYPE_NUMBER_PLAIN MUST

All other number values MUST be serialized as plain JSON numbers, never as $number.

TYPE_NUMBER_ZERO_READ MUST

When deserializing ECSON or reading the plain JSON form, a JSON or JSON5 number that converts to an IEEE 754 double equal to zero MUST be read as positive zero, including -0, -0.0, -1e-400 and, in JSON5, -0x0. Negative zero is only read from { "$number": "-0" }.

Represents undefined, including inside objects and arrays, where JSON.stringify would drop the property or replace the element with null.

TYPE_UNDEFINED MUST

undefined MUST be serialized as { "$undefined": true }.

Represents a RegExp object.

TYPE_REGEXP MUST

A RegExp MUST be serialized as an object with a source string, using the ECMAScript regular expression syntax, and a flags string containing only the characters d, g, i, m, s, u, v and y.

TYPE_REGEXP_VALID MUST

When deserializing, a $regexp value whose flags repeat a character, or whose source and flags are rejected by ECMAScript (for example both u and v, or a source with an unbalanced (), MUST fail (TYPEDEF_VALIDATE), also under TYPE_REGEXP_OPAQUE.

TYPE_REGEXP_OPAQUE MAY

An implementation whose host language cannot represent ECMAScript regular expressions MAY keep $regexp values as opaque values, without compiling source. It still validates source and flags against the ECMAScript syntax (TYPE_REGEXP_VALID), so that every reader accepts the same values.

Represents a Symbol.

TYPE_SYMBOL_UNIQUE MUST

A symbol that is not in the global symbol registry MUST be serialized as a string with its description ("" when it has none), and MUST be deserialized as a new symbol with that description.

TYPE_SYMBOL_REGISTERED MUST

A symbol in the global symbol registry MUST be serialized as an object { "for": key }, where key is its registry key, and MUST be deserialized as the registered symbol for that key (Symbol.for(key)).

TYPE_SYMBOL_WELL_KNOWN MUST

Serializing a well-known symbol (such as Symbol.iterator) MUST fail.

Represents a Set.

TYPE_SET MUST

A Set MUST be serialized as an array of its values, serialized recursively, in iteration order. Deserialization MUST preserve that order.

Represents a Map.

TYPE_MAP MUST

A Map MUST be serialized as an array of [key, value] pairs, both serialized recursively, in iteration order. Keys MAY be any ECSON value. Deserialization MUST preserve that order.

TYPE_SET_MAP_DUPLICATES MUST

When deserializing, a $set with two equal values, or a $map with two equal keys, MUST fail (TYPEDEF_VALIDATE). Equality is ECMAScript SameValueZero on the deserialized values: primitives compare by value ($bigint, $undefined, numbers, where NaN equals NaN and -0 equals 0, strings, booleans, null, and registered symbols with the same key), while objects (plain objects, arrays and every other typed value, such as $date, $regexp, $set and Temporal types) and unique symbols are never equal to each other.

Represents binary data: ArrayBuffer, Node.js Buffer and the typed array family.

TYPE_BYTES MUST

Binary data MUST be serialized as an object with a type string and a data string containing the bytes in Base64, as defined in RFC 4648, section 4, with padding.

TYPE_BYTES_VALID MUST

A $bytes value whose data is not Base64 with padding (without spaces, and with zero padding bits), or whose number of bytes is not a multiple of the element size of its type, MUST fail (TYPEDEF_VALIDATE).

TYPE_BYTES_TYPES MUST

type MUST be one of ArrayBuffer, Buffer, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float16Array, Float32Array, Float64Array, BigInt64Array or BigUint64Array.

TYPE_BYTES_LITTLE_ENDIAN MUST

Typed arrays with elements larger than one byte MUST be serialized with each element in little-endian byte order, regardless of the host platform.

TYPE_BYTES_FALLBACK MAY

An implementation that cannot represent the given type MAY deserialize the value as a plain byte sequence (for example, Buffer as Uint8Array outside Node.js).

Represent the ECMAScript Temporal types, part of ECMAScript since ES2026.

TYPE_TEMPORAL MUST

Temporal values MUST be serialized as strings, using the tag for their type from the table below and the string format that ECMAScript Temporal’s toString() produces with default options, which follows RFC 9557.

Temporal type Tag Example
Temporal.Instant $instant { "$instant": "2024-01-15T00:00:00Z" }
Temporal.ZonedDateTime $zoneddatetime { "$zoneddatetime": "2024-01-15T12:30:00-03:00[America/Sao_Paulo]" }
Temporal.PlainDateTime $plaindatetime { "$plaindatetime": "2024-01-15T12:30:00" }
Temporal.PlainDate $plaindate { "$plaindate": "2024-01-15" }
Temporal.PlainTime $plaintime { "$plaintime": "12:30:00" }
Temporal.PlainYearMonth $plainyearmonth { "$plainyearmonth": "2024-01" }
Temporal.PlainMonthDay $plainmonthday { "$plainmonthday": "01-15" }
Temporal.Duration $duration { "$duration": "P1Y2M3DT4H5M6S" }

TYPE_TEMPORAL_OPAQUE MAY

An implementation whose host language has no equivalent for a Temporal type MAY keep its value as an opaque string.

TYPE_TEMPORAL_SYNTAX MUST

When deserializing, a Temporal string MUST be a string that toString() with default options can produce for its type, whether the implementation has native Temporal or keeps opaque strings. Other strings that Temporal.*.from() accepts, such as 20240115 for a $plaindate or 2024-01-15T00:00:00.000Z for an $instant, MUST fail (TYPEDEF_VALIDATE).

TYPE_TEMPORAL_ISO_YEAR_MONTH_DAY MUST

$plainyearmonth and $plainmonthday values MUST use the ISO 8601 calendar. Serialization MUST fail for values in other calendars, and deserialization MUST fail for strings with any calendar annotation, including [u-ca=iso8601], which toString() never writes.

Source: lingodata/ecson@fe27835 · spec/sections/03-built-in-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.