Function Signature
Parameters
unknown
required
Any JavaScript value to encode (objects, arrays, primitives). The value will be normalized to JSON-compatible types.
EncodeOptions
Optional encoding configuration.
number
default:"2"
Number of spaces per indentation level.
Delimiter
default:"DELIMITERS.comma"
Delimiter to use for tabular array rows and inline primitive arrays.
'off' | 'safe'
default:"'off'"
Enable key folding to collapse single-key wrapper chains. When set to
'safe', nested objects with single keys are collapsed into dotted paths (e.g., data.metadata.items instead of nested indentation).number
default:"Infinity"
Maximum number of segments to fold when
keyFolding is enabled. Controls how deep the folding can go in single-key chains. Values 0 or 1 have no practical effect (treated as effectively disabled).EncodeReplacer
A function to transform or filter values during encoding. Called for the root value and every nested property/element. Return
undefined to omit properties/elements (root cannot be omitted).Returns
string
TOON formatted string representing the input value.
Examples
Related Functions
- encodeLines - Stream encoding line-by-line for large outputs
- decode - Decode TOON format back to JavaScript values
