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:
json2toonandtoon2json - 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)
The encoding commands (json2toon and j2toon convert) additionally support:
--mode– how to encode arrays of objects:auto(default),table, ornested. This option is encoding-only;toon2jsondoes not accept it.
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)mode– how to encode arrays of objects (default is"auto"):"auto"– use a table when all objects share the same scalar fields, otherwise use nested list entries"table"– force tabular output for non-empty arrays whose items are all objects. If those objects do not share the same scalar fields, aValueErroris raised. Primitive arrays (e.g.[1, 2, 3]) and mixed arrays (objects and primitives together) keep their normal representation and never raise."nested"– never use tables; always emit nested list entries
Choosing table vs nested output
By default ("auto") an array of uniform objects becomes a compact table. Pass
mode="nested" to force one entry per object instead, which is useful when you
want to preserve per-object grouping or diff two documents line by line:
from j2toon import json2toon
document = {
"items": [
{"sku": "A1", "qty": 2, "price": 9.99},
{"sku": "B2", "qty": 1, "price": 14.5},
]
}
print(json2toon(document))
# items[2]{sku,qty,price}:
# A1,2,9.99
# B2,1,14.5
print(json2toon(document, mode="nested"))
# items[2]:
# - sku: A1
# qty: 2
# price: 9.99
# - sku: B2
# qty: 1
# price: 14.5
Use mode="table" when you need to guarantee tabular output. The strict rule
only applies to non-empty arrays whose items are all objects: if they do not
share the same scalar fields, a ValueError is raised so you can fix the input
instead of silently getting a different layout. Primitive arrays and mixed
arrays are unaffected and keep their normal representation.
Tables use the field order of the first row for the header. Later rows may list the same fields in any order; they are mapped back onto the first row's order when decoded.
mode is an encoding-only option. It is accepted by json2toon (and the
json2toon / j2toon convert commands) but not by toon2json, whose only
decode-time options are indent and delimiter.
Reserved strings, exponents, and special keys
Values that merely look like other types stay strings: "true", "null",
"123", "1e5", and other numeric-looking tokens are quoted on the way out so
they decode back to strings. Exponents such as 2e-05 and 1e16 are written
bare and decode to floats. Keys containing delimiters or structural characters
(a,b, a:b, a[0], empty strings, leading dashes) are quoted too:
from j2toon import json2toon, toon2json
document = {
"true": "false", # reserved word as a key
"ratio": 2e-05, # exponent number
"a,b": "x:y", # delimiter/structural chars in key and value
}
text = json2toon(document)
# true: "false"
# ratio: 2e-05
# "a,b": "x:y"
assert toon2json(text) == document
json2toon data.json --mode nested # Force nested list entries
json2toon data.json --mode table # Force tables, error if impossible
j2toon convert data.json --mode nested # Same, via the unified CLI
j2toon convert data.json --mode table # Force tables, error if impossible
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
- Vishnu Prasad — vishnuprasadapp@gmail.com
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.
Metadata
Release files for j2toon 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| j2toon-0.1.2.tar.gz | 23.6 kB | Without provenance | Details for j2toon-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| j2toon-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for j2toon-0.1.2-py3-none-any.whl |
Total release size: 38.5 kB
Release files / j2toon-0.1.2.tar.gz
| Download URL | j2toon-0.1.2.tar.gz |
|---|---|
| Size | 23.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d6d5e12ce51dcdb5986eb679c7a9bb924772c058f20ae665e209449b1402311
|
|
BLAKE2b-256 checksum How to use checksums |
d18453f03c3e7adb636d8ba0c7d704ed607d1c2d899848975210f0262dfdad31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / j2toon-0.1.2-py3-none-any.whl
| Download URL | j2toon-0.1.2-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b865b4f559e8a1a62270d196482af6459c0f135772e1f9543f3a57ed289075a
|
|
BLAKE2b-256 checksum How to use checksums |
6addc85688cafafea1986e592e72071808e3c80a5a04242b7b9a1bfaee379275
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for j2toon 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.