Given a deeply nested JSON object, this script splits it up into individual JSON objects with one level of nesting. The child objects are created such that the original JSON can be reconstructed.
Written in Python 3.6.
Child objects have the following naming convention: {parent_name}_{child_attribute_name}
Visit http://shirazhazrat.com/dc-challenge/ to test it through a serverless API, using AWS Lambda, API Gateway, and S3.
To run it locally, simply run:
$ python flatten_json.py -f json_file.json
Output files are saved to './output/*'
Notes:
- ID values are added to every new object.
- Index values are added for arrays containing more than one object.
- Arrays will have their parent attribute name simple-singularized: (remove tailing 's')
$ python reconstruct_json.py --dir ./output
Notes:
- Does not work correctly with files whose attribute names contain underscores.
Cheers.