DecodeOptions interface allows you to customize how TOON format strings are decoded to JavaScript values. All options are optional and have sensible defaults.
Interface
Options
Number of spaces per indentation level. Must match the indentation used when encoding.This tells the decoder how many spaces represent one level of nesting. If your TOON data was encoded with a different indent setting, you must use the same value when decoding.
Example
Example
When
true, enforce strict validation of array lengths and tabular row counts.Strict mode validates that:- Array item counts match the declared length in array headers
- Tabular arrays have exactly the specified number of rows
- No blank lines appear within array/tabular data
- No extra items appear after arrays
false for lenient parsing that tolerates minor formatting issues.Example
Example
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). This pairs with keyFolding: 'safe' in EncodeOptions for lossless round-trips.Path expansion is not supported in streaming decode (
decodeStream and decodeStreamSync). It only works with the standard decode() and decodeFromLines() functions.Example
Example
Type: ResolvedDecodeOptions
The internal type representing fully resolved decoding options with all defaults applied:DecodeStreamOptions
For streaming decode operations, a specialized options interface is available that explicitly omitsexpandPaths:
decode() or decodeFromLines() instead.
Streaming limitations
Streaming limitations
Usage Examples
Basic decoding with custom options
Lenient parsing for imperfect data
Round-trip with key folding
Streaming decode (no path expansion)
Validation Errors
Whenstrict: true (default), the decoder will throw errors for various validation failures:
| Error Type | Description |
|---|---|
| Array length mismatch | Declared array length doesn’t match actual item count |
| Tabular row count mismatch | Number of rows doesn’t match array header declaration |
| Blank lines in arrays | Blank lines found within array/tabular data boundaries |
| Extra list items | More list items found than declared in array header |
| Field count mismatch | Tabular row has wrong number of values for declared fields |
strict: false to disable these validations and parse data in a more lenient manner.
See Also
- EncodeOptions - Options for encoding JavaScript to TOON
- Types - Complete type definitions
- decode() - Main decoding function
- decodeStream() - Streaming decoder
