Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

python save api response to json file append

# Python program to update
# JSON
 
 
import json
 
 
# function to add to JSON
def write_json(new_data, filename='data.json'):
    with open(filename,'r+') as file:
          # First we load existing data into a dict.
        file_data = json.load(file)
        # Join new_data with file_data inside emp_details
        file_data["emp_details"].append(new_data)
        # Sets file's current position at offset.
        file.seek(0)
        # convert back to json.
        json.dump(file_data, file, indent = 4)
 
    # python object to be appended
y = {"emp_name":"Nikhil",
     "email": "nikhil@geeksforgeeks.org",
     "job_profile": "Full Time"
    }
     
write_json(y)
Comment

PREVIOUS NEXT
Code Example
Javascript :: Get JSON Key In Array Alternative Syntax 
Javascript :: How to Compare Strings Using localeCompare 
Javascript :: what is react-instantsearch-dom 
Javascript :: Underscore _.create() Function 
Javascript :: Joining two arrays with lookup 
Javascript :: Backbone This Will Give Error 
Javascript :: react using props and parent state 
Javascript :: finding the smallest number other than 0 in an array javascript 
Javascript :: react-popper-2 
Javascript :: Both This Have The Same Value 
Javascript :: select angular onchange 
Javascript :: jqxAngular 
Javascript :: react axios POST with super constructor parent class 
Javascript :: Another _.extend Example 
Javascript :: react email validation 
Javascript :: get data from json key with special character 
Javascript :: knex js how to group by many items 
Javascript :: upload file to s3 using pre signed url javascript 
Javascript :: slick slider on change 
Javascript :: get aggregate sum value in kendo grid footer jquery 
Javascript :: VM1658:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 
Javascript :: upload file to api angular 
Javascript :: express.js routing 
Javascript :: onScrollBottom 
Javascript :: set timeout with no name 
Javascript :: html video api set speed 
Javascript :: sort used in price high and low using angular 
Javascript :: convert csv to json typescript 
Javascript :: Nyadorera 
Javascript :: document.querySelectorAll(".preview") + forEach 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =