json-flatten is a Python library providing functions to convert a nested JSON object into a single-level dictionary of key-value pairs, and to reconstruct the original JSON object from that flattened representation. It's particularly useful for scenarios like converting JSON for HTML forms or query string parameters. The library is actively maintained, with releases typically addressing bug fixes and minor enhancements. The latest version is 0.3.1.
pip install json-flattenVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to flatten a nested dictionary (representing a JSON object) into a flat dictionary using `flatten()`, and then restore it to its original nested structure using `unflatten()`.
Ensure that the input to `flatten()` is always a dictionary. If you need to flatten a list of dictionaries, iterate over the list and flatten each dictionary individually.
If working with existing flattened data, verify its compatibility with the current `json-flatten` version. Consider re-flattening old data with the new version if issues arise.
Refer to the library's documentation, particularly the 'flattened format' section, to understand the exact key representation if you intend to process or generate flattened data outside of the `json-flatten` library.
Install the library using the correct package name: `pip install json-flatten`
Ensure the input passed to `flatten()` is a valid Python dictionary, typically by loading a JSON string using `json.loads()` first, e.g., `flattened_data = flatten(json.loads(json_string))`
Specify a different delimiter character (e.g., `__` or `|`) when calling both `flatten()` and `unflatten()` to avoid clashes with existing keys: `flattened_data = flatten(my_json, delimiter='__')`
No dependency data recorded yet.