Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active September 17, 2022 11:09
Show Gist options
  • Save narenaryan/b429a0f05625b38e679be95554a27abe to your computer and use it in GitHub Desktop.
Save narenaryan/b429a0f05625b38e679be95554a27abe to your computer and use it in GitHub Desktop.
import json
colors = [
{
"name": "RED",
"foundIn": "soil"
},
{
"name": "GREEN",
"foundIn": "forest"
},
{
"name": "Blue",
"foundIn": "sky"
}
]
# file pointer to a new file colors.json
fp = open("colors.json", "w")
"""
Saves below content to file: colors.json.
[
{
"name": "RED",
"foundIn": "soil"
},
{
"name": "GREEN",
"foundIn": "forest"
},
{
"name": "Blue",
"foundIn": "sky"
}
]
"""
json.dump(colors, fp, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment