toon_codec/types
Core type definitions for the TOON encoder/decoder.
This module defines the JSON value representation, configuration options, and internal types used throughout the library. Represents a JSON value that can be encoded/decoded to TOON format.
This type is compatible with standard JSON representations and preserves key ordering for objects.
Examples
let user = Object([
  #("name", String("Alice")),
  #("age", Number(30.0)),
  #("active", Bool(True)),
])
Delimiter character used to separate values in arrays and tabular rows.
The delimiter determines how inline primitive arrays and tabular data are formatted and parsed. Converts a delimiter to its string representation. Optional marker to prefix array lengths in headers.
When set to HashMarker, arrays render as [#N] instead of [N]. Configuration options for encoding JSON values to TOON format.
Examples
let options = EncodeOptions(
  indent: 2,
  delimiter: Comma,
  length_marker: NoMarker,
)
Returns the default encoding options.
Examples
let options = default_encode_options()
// EncodeOptions(indent: 2, delimiter: Comma, length_marker: NoMarker)
Configuration options for decoding TOON format to JSON values.
Examples
let options = DecodeOptions(indent: 2, strict: True)
Returns the default decoding options.
Examples
let options = default_decode_options()
// DecodeOptions(indent: 2, strict: True)
Internal: Represents a parsed line with depth and metadata.
This opaque type is used internally by the decoder to track line information during parsing. The depth indicates the indentation level. Create a new ParsedLine. Get the depth of a parsed line. Get the content of a parsed line. Get the line number of a parsed line. Get the indent of a parsed line. Internal: Information parsed from an array header line.
This type represents the structured data extracted from headers like:
[3]:(inline primitive array)items[2]:(named array)users[2]{id,name}:(tabular array) Internal: Type of root value in a TOON document.
Types
pub type ArrayHeader {
  ArrayHeader(
    key: option.Option(String),
    length: Int,
    delimiter: Delimiter,
    fields: option.Option(List(String)),
    has_length_marker: Bool,
  )
}
      
      Constructors
- 
          
ArrayHeader( key: option.Option(String), length: Int, delimiter: Delimiter, fields: option.Option(List(String)), has_length_marker: Bool, )Arguments
- key
 - 
                
Optional key name for the array
 - length
 - 
                
Declared array length
 - delimiter
 - 
                
Active delimiter for this array’s scope
 - fields
 - 
                
Optional field names for tabular arrays
 - has_length_marker
 - 
                
Whether the length marker “#” was present
 
 
pub type DecodeOptions {
  DecodeOptions(indent: Int, strict: Bool)
}
      
      Constructors
- 
          
DecodeOptions(indent: Int, strict: Bool)Arguments
- indent
 - 
                
Number of spaces per indentation level (default: 2)
 - strict
 - 
                
Enable strict mode validation (default: True)
 
 
pub type Delimiter {
  Comma
  Tab
  Pipe
}
      
      Constructors
- 
          
CommaComma delimiter “,” (default)
 - 
          
TabTab delimiter (HTAB, U+0009)
 - 
          
PipePipe delimiter “|”
 
pub type EncodeOptions {
  EncodeOptions(
    indent: Int,
    delimiter: Delimiter,
    length_marker: LengthMarker,
  )
}
      
      Constructors
- 
          
EncodeOptions( indent: Int, delimiter: Delimiter, length_marker: LengthMarker, )Arguments
- indent
 - 
                
Number of spaces per indentation level (default: 2)
 - delimiter
 - 
                
Delimiter for arrays and tabular data (default: Comma)
 - length_marker
 - 
                
Optional length marker in array headers (default: NoMarker)
 
 
pub type JsonValue {
  Null
  Bool(Bool)
  Number(Float)
  String(String)
  Array(List(JsonValue))
  Object(List(#(String, JsonValue)))
}
      
      Constructors
- 
          
NullRepresents a null value
 - 
          
Bool(Bool)Represents a boolean value (true or false)
 - 
          
Number(Float)Represents a numeric value (integers and floats are both Float in Gleam)
 - 
          
String(String)Represents a string value
 - 
          
Array(List(JsonValue))Represents an array of JSON values
 - 
          
Object(List(#(String, JsonValue)))Represents an object as an ordered list of key-value pairs
 
pub type LengthMarker {
  NoMarker
  HashMarker
}
      
      Constructors
- 
          
NoMarkerNo length marker (default): [3]
 - 
          
HashMarkerHash marker prefix: [#3]
 
pub opaque type ParsedLine
      
    Values
pub fn default_decode_options() -> DecodeOptions
    
    
  pub fn default_encode_options() -> EncodeOptions
    
    
  pub fn delimiter_to_string(delimiter: Delimiter) -> String
    
    
  pub fn new_parsed_line(
  raw: String,
  depth: Int,
  indent: Int,
  content: String,
  line_number: Int,
) -> ParsedLine
    
    
  pub fn parsed_line_content(line: ParsedLine) -> String
    
    
  pub fn parsed_line_depth(line: ParsedLine) -> Int
    
    
  pub fn parsed_line_indent(line: ParsedLine) -> Int
    
    
  pub fn parsed_line_number(line: ParsedLine) -> Int