Efficient JSON flattening for complex nested structures
Project description
jsonxplode
Efficient JSON flattening for complex nested structures
jsonxplode converts nested JSON structures into flat tabular format while preserving all data, including complex nested arrays and objects with arbitrary depth.
Version Update: v1.2.0
Bug fix
Relational Array Flattening - Arrays of different sizes are now also flattened relationally by default, preserving positional relationships:
Version Update: v1.1.0
Bug fix
Relational Array Flattening - Arrays of the same length are now flattened relationally by default, preserving positional relationships:
Control Relational Array Flattening
Control how arrays are flattened with the relational_array parameter:
# Default - preserves relationships between arrays
flattener = FlattenJson(relational_array=True)
# Independent flattening of arrays
flattener = FlattenJson(relational_array=False)
Example with Relational Flattening (Default)
data = {
"name": "John",
"a": [1, 2, 3],
"b": [1, 2, 3]
}
result = flattener.flatten(data)
Returns:
[
{"name": "John", "a": 1, "b": 1},
{"name": "John", "a": 2, "b": 2},
{"name": "John", "a": 3, "b": 3}
]
Installation
pip install jsonxplode
Usage
from jsonxplode import flatten
# Handles any JSON structure
data = {
"users": [
{"profile": {"name": "John", "settings": {"theme": "dark"}, "location": ["city1", "city2"]}},
{"profile": {"name": "Jane", "settings": {"theme": "light"}}}
]
}
flattened_data = flatten(data)
Returns:
[
{'users.profile.name': 'John', 'users.profile.settings.theme': 'dark', 'user.profile.location': 'city1'},
{'users.profile.name': 'John', 'users.profile.settings.theme': 'dark', 'user.profile.location': 'city2'},
{'users.profile.name': 'Jane', 'users.profile.settings.theme': 'light'}
]
DataFrame Output (Optional)
from jsonxplode import to_dataframe
# Requires pandas to be installed separately
df = to_dataframe(data)
Note: to_dataframe requires pandas (pip install pandas) but the core flatten function has zero dependencies.
Features
- Arbitrary nesting depth - handles deeply nested objects and arrays
- Conflict resolution - automatically manages key path conflicts
- Memory efficient - processes large datasets with minimal overhead
- Zero dependencies - pure Python implementation (core function)
- Array expansion - properly handles nested arrays with row duplication
Performance
- 7,900 rows with 23 columns processed in 0.146 seconds
- Memory usage: ~16MB for above mentioned workload
- Consistent performance across varying data structures
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 jsonxplode-1.2.0.tar.gz.
File metadata
- Download URL: jsonxplode-1.2.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5976e2f5118e26e36e141dfce8d03c9dba83e3bdbc35d5df1a477c3efc2c7c7
|
|
| MD5 |
7bd2a9910e2546f99e129cc871a98634
|
|
| BLAKE2b-256 |
61691d637dd1d9770c3f5e1b6943f3793de34003a8540cc53f3a1ddcc7dd67ee
|
File details
Details for the file jsonxplode-1.2.0-py3-none-any.whl.
File metadata
- Download URL: jsonxplode-1.2.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3c9f2ccef986598576fb16830fdca56dca01dbd1ef986cb3a6f6de98a8b2a21
|
|
| MD5 |
2c232679e10a85bdf4bf8347a3d95fea
|
|
| BLAKE2b-256 |
b1b4af7aa77cafe6c02a25fe98facca4575c5c6fbb5d43f92dd2b87b738486fa
|