Skip to content

Instantly share code, notes, and snippets.

@johnxx
Created June 8, 2019 01:39
Show Gist options
  • Save johnxx/15cb14add6652ac2103a52d483caa0bc to your computer and use it in GitHub Desktop.
Save johnxx/15cb14add6652ac2103a52d483caa0bc to your computer and use it in GitHub Desktop.
import jsonstreams
with jsonstreams.Stream(jsonstreams.Type.object, filename='foo') as my_file:
my_dict = {
'Name': 'Pants',
'Color': 'khaki',
}
for k, v in my_dict.iteritems():
my_file.write(k, v)
with my_file.subobject('Folders') as sub:
sub_dict = {
'Name': 'Pocket',
'Color': 'Invisible'
}
with sub.subobject(sub_dict['Name']) as sub_item:
for k, v in sub_dict.iteritems():
sub_item.write(k, v)
with sub_item.subobject('Folders') as subsub:
subsub_dict = {
'Name': 'Lint',
'Color': 'Pants'
}
with subsub.subobject(subsub_dict['Name']) as subsub_item:
for k, v in subsub_dict.iteritems():
subsub_item.write(k, v)
@johnxx
Copy link
Author

johnxx commented Jun 8, 2019

{
    "Color": "khaki",
    "Name": "Pants",
    "Folders": {
        "Pocket": {
            "Color": "Invisible",
            "Name": "Pocket",
            "Folders": {
                "Lint": {
                    "Color": "Pants",
                    "Name": "Lint"
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment