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:

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
Search Document