Skip to main content

JSON Toon

Convert Python data structures to/from TOON (Token-Oriented Object Notation) - a lightweight, human-readable format optimized for LLM-friendly structured data.

Installation

pip install json-toon

What is TOON?

TOON is a Token-Oriented Object Notation format that represents structured data in a clean, readable way:

  • Nested dictionaries with indentation
  • Tables for lists of objects (using | separators)
  • Comma-separated lists for simple arrays
  • Human-readable and LLM-friendly

Usage

Convert Python Data to TOON Format

from json_toon import json_to_toon

data = {
    "name": "Alice",
    "age": 30,
    "items": ["apple", "banana", "cherry"]
}

toon_string = json_to_toon(data)
print(toon_string)
# Output:
# name: Alice
# age: 30
# items:
#   apple, banana, cherry

Convert TOON Back to Python Data

from json_toon import toon_to_json

toon_text = """
name: Alice
age: 30
items:
  apple, banana, cherry
"""

data = toon_to_json(toon_text)
print(data)
# Output: {'name': 'Alice', 'age': 30, 'items': ['apple', 'banana', 'cherry']}

Convert TOON to JSON String

from json_toon import to_json_str

toon_text = """
name: Alice
age: 30
"""

json_string = to_json_str(toon_text)
print(json_string)
# Output: Pretty-printed JSON string

Tables for Lists of Objects

from json_toon import json_to_toon

users = [
    {"name": "Alice", "age": 30, "city": "NYC"},
    {"name": "Bob", "age": 25, "city": "LA"}
]

toon_string = json_to_toon(users)
print(toon_string)
# Output:
# name | age | city
# Alice | 30 | NYC
# Bob | 25 | LA

API Reference

json_to_toon(data, indent=0)

Convert Python object (dict, list, primitives) to TOON format string.

Parameters:

  • data: Python object to convert
  • indent: Starting indentation level (default: 0)

Returns: TOON-formatted string

toon_to_json(toon_text)

Parse TOON-formatted text back into Python object.

Parameters:

  • toon_text: TOON format string

Returns: Python object (dict, list, or primitive)

to_json_str(toon_text)

Convert TOON text directly to JSON string.

Parameters:

  • toon_text: TOON format string

Returns: Pretty-printed JSON string

Development

To install in development mode:

pip install -e .

License

MIT License - See LICENSE file for details.

Metadata

Release files for json-toon 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-toon 1.0.2
File Size Uploaded
json_toon-1.0.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json-toon 1.0.2
File Interpreter ABI Platform
json_toon-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / json_toon-1.0.2.tar.gz

Download URL json_toon-1.0.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dabc1eb87b513f925005e8af7a42d1481b9498ca40a4279870a141a498532901
BLAKE2b-256 checksum
How to use checksums
8478fbf7b5edb762b7af5f815e083a6e691c6628d6c8ed9bb8c7d1a415b07ab1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / json_toon-1.0.2-py3-none-any.whl

Download URL json_toon-1.0.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8efe4c1e945c9849c5745ca335bc9ff01dbeda04ad880a9a736a594664c0afa
BLAKE2b-256 checksum
How to use checksums
9284ea585bf54380f8945a3a6e65d0af426d8186e5e2495cc58b7fad6fbf0283
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page