Function Signature
Parameters
TOON formatted string to decode.
Optional decoding configuration.
Number of spaces per indentation level. Must match the indentation used when encoding.
When
true, enforce strict validation of array lengths and tabular row counts.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
Parsed JavaScript value (object, array, or primitive).
Examples
Error Handling
Thedecode 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)
Related Functions
- decodeFromLines - Decode from pre-split lines
- encode - Encode JavaScript values to TOON format
