Skip to main content

314

English | 中文

把嵌套 JSON 拍平成点号键,并能原样还原。

安装

pip install 314

用法

from p314 import flatten_json, unflatten_json

doc = {"a": {"b": [{"c": 1}, {"c": 2}]}, "d": 3}

flatten_json(doc)
# {'a.b.0.c': 1, 'a.b.1.c': 2, 'd': 3}

unflatten_json(flatten_json(doc)) == doc   # True

说明

包名以数字开头,导入名是 p314。列表用数字段表示,{"a": [{"b": 1}]} 变 {"a.0.b": 1};空容器保留空值,因此往返无损。unflatten_json 会把数字段还原成列表下标。

许可证

MIT


English

Flatten nested JSON into dotted keys and rebuild it.

Install

pip install 314

Usage

from p314 import flatten_json, unflatten_json

doc = {"a": {"b": [{"c": 1}, {"c": 2}]}, "d": 3}

flatten_json(doc)
# {'a.b.0.c': 1, 'a.b.1.c': 2, 'd': 3}

unflatten_json(flatten_json(doc)) == doc   # True

Notes

The import name is p314 because the distribution starts with a digit. Lists use numeric segments, so {"a": [{"b": 1}]} becomes {"a.0.b": 1}. Empty containers are preserved, making the round trip lossless.

License

MIT

Metadata

Release files for 314 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for 314 0.0.3
File Size Uploaded Provenance
314-0.0.3.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for 314 0.0.3
File Interpreter ABI Platform
314-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / 314-0.0.3.tar.gz

Download URL 314-0.0.3.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f02d837a3e9c568f88dcf21e6311858f6441201fe53e03df38ce3acc357b4848
BLAKE2b-256 checksum
How to use checksums
3efb918e7d21c77438bf053f04cfb5c11e7d529e13062c99b572c9d824844e7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / 314-0.0.3-py3-none-any.whl

Download URL 314-0.0.3-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db84452de1185923a94f5716a75ee660f4d7cd42e11563d1d55cc218b1f56f46
BLAKE2b-256 checksum
How to use checksums
85e0f7319b98dd7c67af706cafceac3389e8874d0b33b29816af87a2077d17cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for 314 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page