how to add new data in json code example
Example 1: how to add element in json object
// base code ----------------------------------------------------------
object["property"] = value;
// or
object.property = value;
// exampel : ----------------------------------------------------------
var myJson = { name: "mamad", family: "mirzaei" }
// i wana to add age
myJson.age = 26
// log =>
console.log( "myJson >>:" ,myJson)
// resalt =>
{ name: "Mamad", family: "Mirzaei", age : 26 }
Example 2: how to add items to an existing json file python
a_dictionary = {"d": 4}
with open("sample_file.json", "r+") as file:
data = json.load(file)
update(a_dictionary)
seek(0)
dump(data, file)