json-flattener
raw JSON → 0.2.0 verified Mon Apr 27 auth: no python
Python library for denormalizing nested dicts or JSON objects to tabular form (CSV, TSV, Excel) and back. Current version 0.2.0, with a new poetry-based build and improved error handling. Maintained by the OBO Foundry community. Releases are occasional.
pip install json-flattener Common errors
error ImportError: No module named 'json_flattener' ↓
cause Misspelled package name or not installed.
fix
Install with: pip install json-flattener
error TypeError: flatten() got an unexpected keyword argument 'separator' ↓
cause Use of deprecated argument name 'separator' instead of 'sep'.
fix
Use sep='.' instead of separator='.'
Warnings
gotcha The default separator is '__' (double underscore), not '.'. Many users expect a dot separator. You can customize with the 'sep' argument. ↓
fix Use flatten(nested, sep='.') for dot notation.
gotcha Flattening a list inside a dict creates keys with numeric indices (e.g., 'b__d__0'). This may not match your schema expectations. ↓
fix Post-process keys or use a different flattening library if you need custom list handling.
Imports
- JsonFlattener
from json_flattener import JsonFlattener - flatten wrong
from json_flattener.flatten import flattencorrectfrom json_flattener import flatten
Quickstart
from json_flattener import flatten
nested = {'a': 1, 'b': {'c': 2, 'd': [3, 4]}}
flat = flatten(nested)
print(flat)
# Output: {'a': 1, 'b__c': 2, 'b__d__0': 3, 'b__d__1': 4}