Skip to main content

Convert Python data to TOON (Token-Oriented Object Notation) - A lightweight, LLM-friendly structured data format

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_toon-1.0.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_toon-1.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file json_toon-1.0.2.tar.gz.

File metadata

  • Download URL: json_toon-1.0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for json_toon-1.0.2.tar.gz
Algorithm Hash digest
SHA256 dabc1eb87b513f925005e8af7a42d1481b9498ca40a4279870a141a498532901
MD5 c64bbcd5c903cf0c47a78486ceecdbd3
BLAKE2b-256 8478fbf7b5edb762b7af5f815e083a6e691c6628d6c8ed9bb8c7d1a415b07ab1

See more details on using hashes here.

File details

Details for the file json_toon-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: json_toon-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for json_toon-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8efe4c1e945c9849c5745ca335bc9ff01dbeda04ad880a9a736a594664c0afa
MD5 5c1b06dc409f77d9bdd820cea481af05
BLAKE2b-256 9284ea585bf54380f8945a3a6e65d0af426d8186e5e2495cc58b7fad6fbf0283

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page