Skip to main content

Function Signature

Decodes TOON format from pre-split lines into a JavaScript value. This is a convenience wrapper around the streaming decoder that builds the full value in memory. Useful when you already have lines as an array or iterable and want the standard decode behavior with path expansion support.

Parameters

Iterable<string>
required
Iterable of TOON lines (without newlines). Can be an array, generator, or any iterable of strings.
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

Use Cases

Pre-split Input

When you already have lines from another source (file streams, network, etc.), decodeFromLines is more efficient than joining and splitting:

Streaming Decode with Full Value

When you want to stream input but need the complete value (with path expansion):

Processing Line Arrays

Comparison with decode()

decodeFromLines is essentially equivalent to:
However, decodeFromLines is more efficient when you already have lines, as it avoids the join and re-split operations.
  • decode - Decode from a complete TOON string
  • encodeLines - Encode to lines for streaming