Skip to main content

Function Signature

Decodes a TOON format string into a JavaScript value.

Parameters

string
required
TOON formatted string to decode.
DecodeOptions
Optional decoding configuration.
number
default:"2"
Number of spaces per indentation level. Must match the indentation used when encoding.
boolean
default:"true"
When true, enforce strict validation of array lengths and tabular row counts.
'off' | 'safe'
default:"'off'"
Enable path expansion to reconstruct dotted keys into nested objects. When set to 'safe', keys containing dots are expanded into nested structures if all segments are valid identifiers (e.g., data.metadata.items becomes nested objects). Pairs with keyFolding='safe' for lossless round-trips.

Returns

JsonValue
Parsed JavaScript value (object, array, or primitive).

Examples

Error Handling

The decode function throws errors for invalid TOON format:
  • Indentation errors (incorrect nesting)
  • Array length mismatches (in strict mode)
  • Invalid syntax (malformed headers, values, etc.)
  • Tabular row count mismatches (in strict mode)