toon_codec/encode
Main encoding module for converting JSON values to TOON format.
This module provides the primary encoding function that coordinates the encoding of any JSON value to TOON format. Encode a JSON value to TOON format string.
This is the main entry point for encoding. It handles all JSON value types:
- Primitives (null, booleans, numbers, strings)
 - Arrays (inline, tabular, or expanded)
 - Objects (flat or nested)
 
Examples
// Simple object
let value = Object([
  #("name", JsonString("Alice")),
  #("age", Number(30.0)),
])
encode_value(value, default_encode_options())
// -> "name: Alice\nage: 30"
// Nested object
let value = Object([
  #("user", Object([
    #("id", Number(1.0)),
    #("name", JsonString("Bob")),
  ])),
])
encode_value(value, default_encode_options())
// -> "user:\n  id: 1\n  name: Bob"
// Array
let value = Array([Number(1.0), Number(2.0), Number(3.0)])
encode_value(value, default_encode_options())
// -> "[3]: 1,2,3"
Values
pub fn encode_value(
  value: types.JsonValue,
  options: types.EncodeOptions,
) -> String