EncodeOptions interface allows you to customize how JavaScript values are encoded to TOON format. All options are optional and have sensible defaults.
Interface
Options
Number of spaces per indentation level. Controls how deeply nested structures are visually indented in the output.
Example
Example
Delimiter to use for separating values in tabular array rows and inline primitive arrays.Available delimiters:
DELIMITERS.comma-,(default)DELIMITERS.tab-\tDELIMITERS.pipe-|
Example
Example
Enable key folding to collapse single-key wrapper chains into dotted paths.When set to
'safe', nested objects with single keys are collapsed into dotted notation (e.g., data.metadata.items instead of nested indentation). This reduces token usage for deeply nested structures.Example
Example
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).Example
Example
A function to transform or filter values during encoding.Called for the root value and every nested property/element. Similar to Parameters:
JSON.stringify’s replacer, but with path tracking. Return undefined to omit properties/elements (root cannot be omitted).Type signature:key- The property key or array index (as string). Empty string ('') for root value.value- The normalizedJsonValueat this location.path- Array representing the path from root to this value.
- The replacement value (will be normalized again), or
undefinedto omit. - For root value, returning
undefinedmeans “no change” (don’t omit root).
Examples
Examples
Type: ResolvedEncodeOptions
The internal type representing fully resolved encoding options with all defaults applied:Usage Examples
Basic encoding with custom options
Streaming with options
Advanced replacer usage
See Also
- DecodeOptions - Options for decoding TOON to JavaScript
- Types - Complete type definitions
- encode() - Main encoding function
