Skip to main content

Python helpers to convert between JSON-compatible data and TOON.

Project description

j2toon

j2toon is a simple Python tool that converts JSON data into TOON format and converts it back. TOON is a human-readable data format that's easier to read and edit than JSON. You don't need to learn all the TOON rules—the tool automatically chooses the best format for your data.

Why use j2toon?

  • Easy to use – just two simple functions: json2toon and toon2json
  • Smart formatting – automatically formats your data in the most readable way (tables, lists, or nested blocks)
  • No extra packages needed – works with just Python, no additional libraries required

Installation

Install j2toon using pip or uv:

pip install j2toon

or

uv install j2toon

Usage

Here's a simple example showing how to convert JSON to TOON and back:

from j2toon import json2toon, toon2json

# Start with some JSON data
document = {
    "items": [
        {"sku": "A1", "qty": 2, "price": 9.99},
        {"sku": "B2", "qty": 1, "price": 14.5},
    ],
    "tags": ["hardware", "beta"],
}

# Convert JSON to TOON format
text = json2toon(document)
print(text)
# items[2]{sku,qty,price}:
#   A1,2,9.99
#   B2,1,14.5
# tags[2]: hardware,beta

# Convert back to JSON to verify it works
assert toon2json(text) == document

Command line

You can also use j2toon from the command line:

json2toon data.json -o data.toon        # Convert JSON to TOON
toon2json data.toon --indent 2          # Convert TOON back to JSON

Both commands support these options:

  • --indent – how many spaces to use for indentation (default is 2)
  • --delimiter – what character to use to separate values (default is comma)

Options

When using the functions in Python, you can customize the output with these options:

  • indent – how many spaces to use for each level of nesting (default is 2)
  • delimiter – what character to use to separate values in lists and tables. You can use "," (comma), "\t" (tab), or "|" (pipe)

Development

To set up the project for development:

pip install -e .
pytest

Requirements:

  • Python 3.9 or higher
  • Tests are in the tests/ folder and check that conversions work correctly in both directions

Maintainer

Learn More

For complete details about the TOON format, check out the official TOON specification. This tool focuses on the most commonly used parts of TOON to keep things simple and reliable.

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

j2toon-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

j2toon-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file j2toon-0.1.0.tar.gz.

File metadata

  • Download URL: j2toon-0.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for j2toon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 50968061e9a4f1a45b0b12cb0b35dd6ba59fed22cd5a1a1ecd8ea2c6c541dbbb
MD5 d4b3404e6788f91362fe29092f7c5562
BLAKE2b-256 6b99a460f365513710d1a070ae80d0eb23c654de858cd4016675a670ba2cd245

See more details on using hashes here.

File details

Details for the file j2toon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: j2toon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for j2toon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f53c0f8295cca000966afa2b824f0a730058098879caf16915a521c10760484
MD5 8bab8ada5fcc635a5f4570d544f2b0a8
BLAKE2b-256 6a0baac183426da467e96d238d67cef65359834c95ec56f41cf3925380e9615b

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