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 pip 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.1.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.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: j2toon-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d5235bf43f335049555d6ad304bffce4f4a77f82cb6387ad005fec029a1fe5de
MD5 e39b7c55c23ae579d2677090cbb7bea6
BLAKE2b-256 28b2a5c4b9cfe6571447cc13324379e005949d077c78c86a8fe887688a1b5ce1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: j2toon-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df61dcb6f95f37b6c03540c448ac193a90dd552676f3f153008b2558b01bab83
MD5 1efd73bd26c5223bba24430c9578c4a0
BLAKE2b-256 08512fe01437f82b263a6a0b2d9a45803b0e244cef017a36dcffb6689bb3f84f

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