Function Signature
Parameters
Any JavaScript value to encode (objects, arrays, primitives). The value will be normalized to JSON-compatible types.
Optional encoding configuration.
Number of spaces per indentation level.
Delimiter to use for tabular array rows and inline primitive arrays.
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).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).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
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
