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")])decode returns OrderedDict{String,Any} objects and Vector{Any} arrays, and throws an ErrorException naming the line on invalid input. Pass EncodeOptions to encode and DecodeOptions to decode through the options keyword, e.g. encode(data; options = EncodeOptions(delimiter = TAB)) – Options lists them.
Targets TOON spec v4.4, and the test suite runs the spec's conformance fixtures.
- Integers decode to
Int, orBigIntbeyond its range, and other numbers toFloat64– a tokenFloat64can't represent (e.g.1e999or1e-400) decodes as a string; on encode, integers print in full, other numbers with the shortest digits of theirFloat64value, and finite reals beyond theFloat64range (e.g.big"1e400") as a quoted string of theirBigFloatvalue in exponent form (§4) - Dicts,
NamedTuples, and vectors or tuples ofPairs encode as objects – other arrays (a matrix in column-major order), tuples, and sets encode as arrays,NaNand±Infasnull, strings that are not valid Unicode throw anArgumentError, and anything else (Symbol,Date,missing) encodes as itsstringform (§3)
Releases follow SemVer: a new spec MINOR version ships as a MINOR release, even when it changes how hand-written input decodes, and a MAJOR release means an API break or a new spec MAJOR version.
- 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