Skip to main content
The 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
default:2
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.
boolean
default:true
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
Set to false for lenient parsing that tolerates minor formatting issues.
'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). 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.

Type: ResolvedDecodeOptions

The internal type representing fully resolved decoding options with all defaults applied:
This type is used internally by the decoder after resolving all option defaults. You typically don’t need to use this type directly.

DecodeStreamOptions

For streaming decode operations, a specialized options interface is available that explicitly omits expandPaths:
Path expansion requires buffering the entire input, which contradicts the streaming model. If you need path expansion, use decode() or decodeFromLines() instead.

Usage Examples

Basic decoding with custom options

Lenient parsing for imperfect data

Round-trip with key folding

Streaming decode (no path expansion)

Validation Errors

When strict: true (default), the decoder will throw errors for various validation failures: Set strict: false to disable these validations and parse data in a more lenient manner.

See Also