Flatten nested JSON/dicts into dot-notation keys and unflatten back
Project description
philiprehberger-flatten-json
Flatten nested JSON/dicts into dot-notation keys and unflatten back.
Installation
pip install philiprehberger-flatten-json
Usage
from philiprehberger_flatten_json import flatten, unflatten
nested = {"a": {"b": {"c": 1}}, "d": [2, 3]}
flatten(nested)
# {"a.b.c": 1, "d.0": 2, "d.1": 3}
unflatten({"a.b.c": 1, "d.0": 2, "d.1": 3})
# {"a": {"b": {"c": 1}}, "d": [2, 3]}
# Custom separator
flatten(nested, separator="/")
# {"a/b/c": 1, "d/0": 2, "d/1": 3}
# Max depth
flatten(nested, max_depth=1)
# {"a": {"b": {"c": 1}}, "d": [2, 3]}
API
flatten(data, separator=".", max_depth=0)— Flatten nested structureunflatten(data, separator=".")— Restore nested structure
License
MIT
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 philiprehberger_flatten_json-0.1.1.tar.gz.
File metadata
- Download URL: philiprehberger_flatten_json-0.1.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22ea0aa87ec2173329b40884eb4aca24fce7ecef2a8df94932ec2a5f8730b3c6
|
|
| MD5 |
9e5230b97ee54263ec3420f9d620a8ec
|
|
| BLAKE2b-256 |
61a4581a26c4c7dc83ea627649b424c2c553ea0314674705b517f0c0424862fc
|
File details
Details for the file philiprehberger_flatten_json-0.1.1-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_flatten_json-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7172fa2db1ee21a91f3bdde432e3a49adb0b6c93f17d7dd4a5dac282e0e2652
|
|
| MD5 |
128dfb839396b0edb3235ed812b37847
|
|
| BLAKE2b-256 |
a45f25f09840b59ebe704c7eb501c9eadeb2a4410e92ee786c71428fb7f9358f
|