Data Types
Complete reference for all JSON6 data types, their semantics, and usage patterns.
TL;DR: JSON6 supports six data types: objects, arrays, strings, numbers, booleans, and null. These map directly to JavaScript types, with JSON6 adding extended syntax for strings and numbers.
Type Overview
JSON6 has the same six data types as JSON, with extended syntax for strings and numbers. All types map directly to JavaScript equivalents when parsed.
| JSON6 Type | JavaScript Type | Description | JSON6 Extensions |
|---|---|---|---|
| Object | object | Key-value pairs | Unquoted keys, trailing commas |
| Array | Array | Ordered list | Trailing commas |
| String | string | Text data | Single quotes, multi-line, hex escapes |
| Number | number | Numeric data | Hex, Infinity, NaN, flexible decimals |
| Boolean | boolean | True or false | None |
| Null | null | No value | None |
Type Hierarchy
JSON6Value ├── JSON6Object { ... } ├── JSON6Array [ ... ] ├── JSON6String "..." or '...' ├── JSON6Number 42, 0xFF, Infinity, NaN ├── JSON6Boolean true, false └── JSON6Null nullObjects
Objects are unordered collections of name/value pairs. They are the primary structure for representing complex data in JSON6.
Characteristics
Structure
- Enclosed in curly braces
{} - Zero or more key-value pairs
- Pairs separated by commas
- Keys and values separated by colon
Key Rules
- Can be unquoted identifiers
- Can be single or double quoted
- Duplicate keys allowed (last wins)
- Order is not guaranteed
Examples
// Empty object {} // Simple object with unquoted keys { name: 'John', age: 30, active: true, } // Nested objects { user: { profile: { name: 'Alice', email: '[email protected]', }, }, } // Mixed key styles { unquoted: 1, 'single-quoted': 2, "double-quoted": 3, }JavaScript Mapping
JSON6 objects parse to JavaScript plain objects:
import JSON6 from 'json6'; const obj = JSON6.parse(`{ name: 'John', age: 30, }`); console.log(typeof obj); // 'object' console.log(obj.name); // 'John' console.log(Object.keys(obj)); // ['name', 'age']Arrays
Arrays are ordered sequences of values. They maintain insertion order and can contain values of any type, including mixed types.
Characteristics
Structure
- Enclosed in square brackets
[] - Zero or more values
- Values separated by commas
- Order is preserved
Value Rules
- Any JSON6 value type allowed
- Mixed types allowed
- Nested arrays allowed
- Trailing comma allowed
Examples
// Empty array [] // Simple array [1, 2, 3, 4, 5] // Array with trailing comma [ 'apple', 'banana', 'cherry', ] // Mixed types [ 'string', 42, true, null, { nested: 'object' }, ['nested', 'array'], ] // Nested arrays [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ]JavaScript Mapping
const arr = JSON6.parse(`[1, 2, 3,]`); console.log(Array.isArray(arr)); // true console.log(arr.length); // 3 console.log(arr[0]); // 1Strings
Strings are sequences of Unicode characters. JSON6 extends JSON strings with single quotes, additional escape sequences, and multi-line support.
Quote Styles
Double Quotes (JSON compatible)
"Hello, World!" "Contains 'single' quotes" "Escape \"doubles\""Single Quotes (JSON6)
'Hello, World!' 'Contains "double" quotes' 'Escape \'singles\''Multi-line Strings
Strings can span multiple lines by escaping the line terminator:
{ poem: 'Roses are red, \ Violets are blue, \ JSON6 is awesome, \ And so are you!', } // Parses to: "Roses are red, Violets are blue, JSON6 is awesome, And so are you!"Escape Sequences
Standard Escapes
"Tab:\tNewline:\n" "Carriage return:\r" "Backslash: \\" "Quote: \"" 'Apostrophe: \''Unicode Escapes
// Unicode escape "\u0041" // "A" "\u4e2d\u6587" // "中文" // Hex escape (JSON6) "\x41" // "A"String Semantics
- Strings are immutable sequences of UTF-16 code units
- Empty strings (
""or'') are valid - Surrogate pairs represent characters outside the BMP
- Line terminators must be escaped (except with
\continuation)
JavaScript Mapping
const str = JSON6.parse(`'Hello, World!'`); console.log(typeof str); // 'string' console.log(str.length); // 13 console.log(str[0]); // 'H'Numbers
Numbers in JSON6 follow IEEE 754 double-precision floating-point format. JSON6 extends JSON numbers with hexadecimal notation, special values, and flexible decimal syntax.
Number Formats
Decimal (JSON compatible)
42 // Integer -17 // Negative 3.14159 // Decimal 2.5e10 // Exponential 1e-5 // Negative exponentExtended (JSON6 only)
0xFF // Hexadecimal .5 // Leading decimal 5. // Trailing decimal +10 // Explicit positive Infinity // Positive infinity NaN // Not a NumberSpecial Values
Infinity
Represents positive infinity. Can be prefixed with - for negative infinity or + for explicit positive.
Infinity // Positive infinity -Infinity // Negative infinity +Infinity // Explicit positiveNaN (Not a Number)
Represents an undefined or unrepresentable numeric value.
NaN // Not a Number JSON Serialization: Infinity and NaN cannot be represented in standard JSON. When stringifying with JSON.stringify(), they become null.
Precision Limits
JSON6 numbers follow IEEE 754 double-precision limits:
| Property | Value | JavaScript Constant |
|---|---|---|
| Max safe integer | 9,007,199,254,740,991 | Number.MAX_SAFE_INTEGER |
| Min safe integer | -9,007,199,254,740,991 | Number.MIN_SAFE_INTEGER |
| Max value | ~1.8 x 10308 | Number.MAX_VALUE |
| Min positive value | ~5 x 10-324 | Number.MIN_VALUE |
JavaScript Mapping
const num = JSON6.parse(`0xFF`); console.log(num); // 255 console.log(typeof num); // 'number' const inf = JSON6.parse(`Infinity`); console.log(inf); // Infinity console.log(inf === Infinity); // true const nan = JSON6.parse(`NaN`); console.log(Number.isNaN(nan)); // trueBooleans
Booleans represent logical true/false values. JSON6 booleans are identical to JSON booleans with no extensions.
Boolean Values
{ enabled: true, disabled: false, }Characteristics
- Only two literal values:
trueandfalse - Case-sensitive (must be lowercase)
- Not quoted (they are literals, not strings)
Note: True, TRUE, "true", 1 are NOT valid boolean values. Only lowercase true and false are accepted.
JavaScript Mapping
const bool = JSON6.parse(`true`); console.log(bool); // true console.log(typeof bool); // 'boolean' console.log(bool === true); // trueNull
Null represents the intentional absence of any value. JSON6 null is identical to JSON null with no extensions.
Null Literal
{ optional: null, missing: null, }Characteristics
- Only one literal value:
null - Case-sensitive (must be lowercase)
- Distinct from
undefined(which doesn't exist in JSON6)
Common Use Cases
{ // Explicitly unset value middleName: null, // Placeholder for future value metadata: null, // Cleared/deleted value previousOwner: null, }JavaScript Mapping
const value = JSON6.parse(`null`); console.log(value); // null console.log(value === null); // true console.log(typeof value); // 'object' (JavaScript quirk)Ready to Start Using JSON6?
Check out our getting started guide or explore real-world examples.