Encodes Julia values to TOON (Token-Oriented Object Notation) and decodes TOON back. TOON is a compact, indentation-based encoding of the JSON data model for LLM input.
using Pkg; Pkg.add("ToonFormat")using ToonFormat
users = [(id = 1, name = "Ada", role = "admin"), (id = 2, name = "Bob", role = "user")]
toon = encode((users = users,))
# users[2]{id,name,role}:
# 1,Ada,admin
# 2,Bob,user
decode(toon)
# OrderedDict("users" => [OrderedDict("id" => 1, "name" => "Ada", "role" => "admin"), OrderedDict("id" => 2, "name" => "Bob", "role" => "user")])Pass EncodeOptions to encode and DecodeOptions to decode through the options keyword, e.g. encode(data; options = EncodeOptions(delimiter = TAB)):
| Option | Default | Description |
|---|---|---|
indent |
2 |
Spaces per indentation level (encode and decode) |
delimiter |
COMMA |
Array delimiter: COMMA, TAB, or PIPE (encode) |
keyFolding |
"off" |
"safe" folds chains of single-key objects into dotted keys (encode) |
flattenDepth |
typemax(Int) |
Maximum segments in a folded key (encode) |
strict |
true |
Raise the strict-mode errors of spec §14 (decode) |
expandPaths |
"off" |
"safe" expands dotted keys into nested objects (decode) |
Targets TOON spec v3.0, and the test suite runs the spec's conformance fixtures.
- Integers decode to
Int64and other numbers toFloat64– tokens outside that domain (e.g.99999999999999999999,1e999) decode as strings (§2) - Dicts,
NamedTuples, and vectors or tuples ofPairs encode as objects – other arrays, tuples, and sets encode as arrays,NaNand±Infasnull, and anything else (Symbol,Date,missing) as itsstringform (§3)
- Specification: SPEC.md – Normative rules and conformance checklists
- Format Overview: toonformat.dev – Every form with examples
- Other Implementations: toonformat.dev – TOON in other languages
- API Reference: toon-format.github.io/ToonFormat.jl – Options and the
encodeanddecodedocstrings
See CONTRIBUTING.md for the development setup and pull request guidelines.
MIT License © 2025-PRESENT Sébastien Celles