working with json files python code example
Example 1: open json file python
import json
with open('data.txt') as json_file:
data = json.load(json_file)
Example 2: json load from file python 3
import json
with open('file_to_load.json', 'r') as file:
data = json.load(file)
Example 3: python json file operations
import json
with open("jsonfile.json", "r") as jsonFile:
data = json.load(jsonFile)
'''
Example Json File:
[{"name": "Bill", "age": 20},
{"name": "Mary", "age": 31},
{"name": "Jake", "age": 19}]
'''
data[1]["age"] = 32
'''
Now the data variable is:
[{"name": "Bill", "age": 20},
{"name": "Mary", "age": 32},
{"name": "Jake", "age": 19}]
'''
with open("jsonfile.json", "w") as fileJson:
json.dump(data, fileJson)
Example 4: Json in python
{
"Icons":{
"app icon": "your icon.ico",
"eg icon": "eg.ico"
}
}