A simple library to convert JSON data into Pandas DataFrames.
Project description
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.
Project details
Release history Release notifications | RSS feed
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_to_frame-0.0.6.tar.gz.
File metadata
- Download URL: json_to_frame-0.0.6.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f0a28c0092b8fb7fb18515b8e6e29f724ad2e9cbe91206db477c846abf0b8be
|
|
| MD5 |
5e391f5f349115f7009e1bb91bc2de86
|
|
| BLAKE2b-256 |
ca447e67b712579f7ac168be5aec70f98e2f0354811c5fe8d8b0eafb4a3c0726
|
File details
Details for the file json_to_frame-0.0.6-py3-none-any.whl.
File metadata
- Download URL: json_to_frame-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13ec6d396da309ff7c3193891f9d3a96638d507e36c02d41014ceb17599e5324
|
|
| MD5 |
bc0201903cf2141be5b3dbad6824c941
|
|
| BLAKE2b-256 |
01cb9af9fc8f7da2b42864ede75e6bff39eefd5c3d471c07e5f63cf444dc809d
|