Skip to main content

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 structure
  • unflatten(data, separator=".") — Restore nested structure

License

MIT

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

philiprehberger_flatten_json-0.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_flatten_json-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_flatten_json-0.1.1.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_flatten_json-0.1.1.tar.gz
Algorithm Hash digest
SHA256 22ea0aa87ec2173329b40884eb4aca24fce7ecef2a8df94932ec2a5f8730b3c6
MD5 9e5230b97ee54263ec3420f9d620a8ec
BLAKE2b-256 61a4581a26c4c7dc83ea627649b424c2c553ea0314674705b517f0c0424862fc

See more details on using hashes here.

File details

Details for the file philiprehberger_flatten_json-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_flatten_json-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7172fa2db1ee21a91f3bdde432e3a49adb0b6c93f17d7dd4a5dac282e0e2652
MD5 128dfb839396b0edb3235ed812b37847
BLAKE2b-256 a45f25f09840b59ebe704c7eb501c9eadeb2a4410e92ee786c71428fb7f9358f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page