JSON to Pandas Dataframe
Convert nested JSON objects into flat pandas DataFrames with a simple Python API.
Overview
This package helps you transform JSON-like payloads into tabular data that is easier to inspect, analyze, and export.
It supports:
- Python dictionaries and lists
- JSON strings
- JSON files
- Deeply nested structures containing dicts, lists, tuples, scalars,
null, and empty collections
Installation
Install from source in editable mode:
pip install -e .
Or install runtime dependencies directly:
pip install -r requirements.txt
Quick Start
from json2df.json2df import DeepNestedHandler, LoadInfo
json_file = "data/svg_example.json"
payload = LoadInfo(file=json_file).get_data()
df = DeepNestedHandler(json_data=payload).convert_to_df()
print(df.head())
API
LoadInfo
Loads JSON-compatible input from either:
info: a Pythondict/listor JSONstrfile: path to a JSON file
Example:
from json2df.json2df import LoadInfo
payload_from_file = LoadInfo(file="data/sample_donut_data.json").get_data()
payload_from_str = LoadInfo(info='{"a": 1, "b": 2}').get_data()
DeepNestedHandler
Flattens nested data into a pandas DataFrame.
Example:
from json2df.json2df import DeepNestedHandler
payload = {
"name": "John",
"cars": [
{"model": "BMW 230", "mpg": 27.5},
{"model": "Ford Edge", "mpg": 24.1}
]
}
df = DeepNestedHandler(payload).convert_to_df()
print(df)
Behavior Notes
- Nested keys are flattened using underscore-separated paths.
- Arrays generate multiple rows when needed.
- For top-level JSON arrays, each item is flattened and concatenated.
- Empty lists are represented with
NaNvalues in the corresponding column.
Running Tests
Run all tests:
python3 -m pytest -v
Run fixture coverage tests only:
python3 -m pytest -v test/test/test_json_fixtures.py
If you want to view DataFrame output from print(...) statements during tests:
python3 -m pytest -v -s test/test/test_json_fixtures.py
Project Structure
src/json2df/
__init__.py
json2df.py
test/data/
*.json
test/test/
test_json_fixtures.py
License
MIT License.
Metadata
Release files for json-to-frame 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| json_to_frame-0.0.6.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| json_to_frame-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / json_to_frame-0.0.6.tar.gz
| Download URL | json_to_frame-0.0.6.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f0a28c0092b8fb7fb18515b8e6e29f724ad2e9cbe91206db477c846abf0b8be
|
|
BLAKE2b-256 checksum How to use checksums |
ca447e67b712579f7ac168be5aec70f98e2f0354811c5fe8d8b0eafb4a3c0726
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / json_to_frame-0.0.6-py3-none-any.whl
| Download URL | json_to_frame-0.0.6-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13ec6d396da309ff7c3193891f9d3a96638d507e36c02d41014ceb17599e5324
|
|
BLAKE2b-256 checksum How to use checksums |
01cb9af9fc8f7da2b42864ede75e6bff39eefd5c3d471c07e5f63cf444dc809d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|