append to json file python code example

Example 1: insert json file in python

a_dictionary = {"d": 4}

with open("sample_file.json", "r+") as file:
    data = json.load(file)	# get data from file
    update(a_dictionary)
    seek(0)
    json.dump(data, file)	# insert data in file

Example 2: push json into json

//create object
var myObj = {
    "artist" : artist,    //your artist variable
    "song_name" : title   //your title variable
};
//push the object to your array
favorites.push( myObj );

Example 3: add item to json file python

import json
with open('file.json', 'a') as outfile:
    outfile.write(json.dumps(data))
    outfile.write(",")
    outfile.close()

Example 4: 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)

Example 5: javascript append to existing json

let test = {
		name: 'NN',
  		email: '[email protected]'
};

test.phone = '234654234';

// result { "name": "NN", "email": "[email protected]", "phone": "234654234" }