I am trying to build out a JSON export mirrored on this example:
import json data = {} data['people'] = [] data['people'].append({ 'name': 'Scott', 'website': 'stackabuse.com', 'from': 'Nebraska' }) with open('data.txt', 'w') as outfile: json.dump(data, outfile)
However, I wish for there to be more nested {} than just the one above, but cannot seem to figure out how to do that. This is what I'd like the JSON to look like:
{ "people":{ "Citizens":{ "Workers":{ "wage":"34", "id":"1 of 2" }, "non-workers":{ "wage":"0", "id":"2 of 2" } } } }
Can anyone help me? Thank you!
https://stackoverflow.com/questions/66979023/looking-to-export-json-in-python-using-multiple-nested-blocks April 07, 2021 at 11:04AM
没有评论:
发表评论