I have a code which get nested object and remove all nesting (make the object flat):
def flatten_json(y):
\"\"\"
@param y: Unflated Json
@return: Fla
I think you're looking for something like this?
import json
def create_jsonlines(original):
if isinstance(original, str):
original = json.loads(original)
return '\n'.join([json.dumps(original[outer_key], sort_keys=True)
for outer_key in sorted(original.keys(),
key=lambda x: int(x))])
# Added fake record to prove order is sorted
inp = {
"3": {"code": "en-FR", "id": 76, "name": "French", "languageName": "French"},
"0": {"code": "en-GB", "id": 77, "languageName": "English", "name": "English"},
"1": {"code": "de-DE", "id": 78, "languageName": "Deutsch", "name": "German"}
}
output = create_jsonlines(inp)
print(output)