TOONS¶
Fast TOON (Token Oriented Object Notation) parsing and serialization for Python, implemented in Rust.
TOONS mirrors the json module API: loads, load, dumps, dump, plus
to_json for converting TOON to JSON.
Install¶
Parse and serialize¶
import toons
data = toons.loads("""
name: Alice
age: 30
tags[3]: admin,developer,ops
""")
print(data)
# {'name': 'Alice', 'age': 30, 'tags': ['admin', 'developer', 'ops']}
print(toons.dumps({"name": "Bob", "active": True}))
# name: Bob
# active: true
Read and write files¶
import toons
payload = {"users": [{"id": 1, "name": "A"}, {"id": 2, "name": "B"}]}
with open("users.toon", "w") as f:
toons.dump(payload, f)
with open("users.toon", "r") as f:
loaded = toons.load(f)
print(loaded == payload)
# True
Convert to JSON¶
import toons
print(toons.to_json("users[2]{id,name}:\n 1,A\n 2,B", indent=2))
# {
# "users": [
# {
# "id": 1,
# "name": "A"
# },
# {
# "id": 2,
# "name": "B"
# }
# ]
# }
Specification¶
TOONS implements TOON specification v4.1, validated on every build against the official conformance fixtures from spec tag v4.1.1.
import toons
print(toons.__toon_spec__) # 4.1 specification version
print(toons.__version__) # 0.8.0 library version
Learn next¶
- Data Types - how Python values map to TOON
- Complex Examples - delimiters, tabular forms, strict mode
- API Reference - full signatures