Python library and CLI app that translates arbitrarily-nested JSON into CSV
Project description
json-tabulate
json-tabulate is a Python library and CLI app that you can use to translate an arbitrarily-nested JSON object—or an array of those objects—into a flat CSV table.
graph LR
json_obj[JSON<br>object] --> app_1[json-tabulate] --> csv_single[CSV<br>1 header row + 1 data row]
json_list[JSON<br>array of N objects] --> app_2[json-tabulate] --> csv_multi[CSV<br>1 header row + N data rows]
Example
It translates this (arbitrarily-nested JSON object):
{
"a": 1,
"b": {
"d": "f",
"e": ["g", "h", "i"]
},
"c": 2
}
Into this (CSV table):
Show/hide CSV string
$.a,$.b.d,$.b.e[0],$.b.e[1],$.b.e[2],$.c
1,f,g,h,i,2
| $.a | $.b.d | $.b.e[0] | $.b.e[1] | $.b.e[2] | $.c |
|---|---|---|---|---|---|
| 1 | f | g | h | i | 2 |
Each column names is a JSONPath expression indicating where the values in that column came from.
Usage
Python library
pip install json-tabulate
>>> from json_tabulate.core import translate_json
>>> translate_json(r'{"name": "Ken", "age": 26}')
'$.age,$.name\n26,Ken\n'
CLI app
Here's the usage string displayed by the CLI app:
json-tabulate --help
Usage: json-tabulate [OPTIONS] [JSON_STRING]
Translate JSON into CSV.
Usage examples:
• json-tabulate '{"name": "Ken", "age": 26}' (specify JSON via argument)
• echo '{"name": "Ken", "age": 26}' | json-tabulate (specify JSON via STDIN)
• cat input.json | json-tabulate > output.csv (write CSV to file)
╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ json_string [JSON_STRING] JSON string to translate. If not provided, │
│ program will read from STDIN. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --version Show version number and exit. │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
Development
Show/hide developer documentation
Using VS Code? The file,
.vscode/tasks.json, contains VS Code task definitions for several of the commands shown below. You can invoke those tasks via the command palette, or—if you have the Task Runner extension installed—via the "Task Runner" panel.
Setup Python virtual environment
Here's how you can create a Python virtual environment and install the Python dependencies within it:
uv sync
Lint Python source code
uv run ruff check --fix
# Other option: Do a dry run.
uv run ruff check
Format Python source code
uv run ruff format
# Other option: Do a dry run.
uv run ruff format --diff
Check data types
uv run mypy
The default configuration is defined in
pyproject.toml.
Run tests
uv run pytest
# Other option: Run tests and measure code coverage.
uv run pytest --cov
The default configuration is defined in
pyproject.toml.
Build distributable package
uv build
The build artifacts will be in the
dist/directory.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file json_tabulate-0.1.1.tar.gz.
File metadata
- Download URL: json_tabulate-0.1.1.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c2f3997ad738f76562da0f32e928077a5660499f87df152ca129b80ba95c0f5
|
|
| MD5 |
7db4e3aaa8c908d0250cd34a6f293406
|
|
| BLAKE2b-256 |
0021c64eba065bf65748dedffa4301fd700ca26563646db7897b7cc6927040c7
|
Provenance
The following attestation bundles were made for json_tabulate-0.1.1.tar.gz:
Publisher:
build-and-publish-package.yml on eecavanna/json-tabulate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_tabulate-0.1.1.tar.gz -
Subject digest:
7c2f3997ad738f76562da0f32e928077a5660499f87df152ca129b80ba95c0f5 - Sigstore transparency entry: 525111652
- Sigstore integration time:
-
Permalink:
eecavanna/json-tabulate@7a751e73280da7ead805fdcaedafc768524cfac4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/eecavanna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish-package.yml@7a751e73280da7ead805fdcaedafc768524cfac4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file json_tabulate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: json_tabulate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db6543412257705b574e21ce6fad853dd65bd6038b8a8d6e16a826c28adf9a5d
|
|
| MD5 |
0ad73e25b99c93a0cf5e16d1e5436ee0
|
|
| BLAKE2b-256 |
62aec6faca8aaa066f1421e7d5bbddc2fc987e8f818d63b98f827a92472372fb
|
Provenance
The following attestation bundles were made for json_tabulate-0.1.1-py3-none-any.whl:
Publisher:
build-and-publish-package.yml on eecavanna/json-tabulate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_tabulate-0.1.1-py3-none-any.whl -
Subject digest:
db6543412257705b574e21ce6fad853dd65bd6038b8a8d6e16a826c28adf9a5d - Sigstore transparency entry: 525111671
- Sigstore integration time:
-
Permalink:
eecavanna/json-tabulate@7a751e73280da7ead805fdcaedafc768524cfac4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/eecavanna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish-package.yml@7a751e73280da7ead805fdcaedafc768524cfac4 -
Trigger Event:
release
-
Statement type: