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.0.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.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_flatten_json-0.1.0.tar.gz
Algorithm Hash digest
SHA256 db60b89854765006b33f028c08b1751f76e1a0a067c8c82c05b7cf56370dcb6d
MD5 ffb991fad98a5a9f734c85ba896c55d1
BLAKE2b-256 ed7de9625503e479b800f1d683782fc4940e4e09b6d6f236c13cab2548ca494e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_flatten_json-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4992eb032aa19f52e74bdeef17fe20acc7a03263c24eba07e185c3731b417ec
MD5 c594e88542644ae63e9c53535083a6fa
BLAKE2b-256 fcf7a109d8a069ef07c08a927df4e5a464ed286f14b8f07f92ec22640571b6bf

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