Append to JSON file using Python
Last Updated :
03 Jul, 2025
JSON (JavaScript Object Notation) is a lightweight data format that stores data as key-value pairs within curly braces {}. Python's json module makes it easy to work with JSON data, whether you are parsing JSON strings, converting Python objects to JSON, or appending new data to existing JSON files.
Key Functions in json
Module:
1. json.loads()
Parses a JSON string and returns a Python dictionary.
Syntax: json.loads(json_string)
Parameter: It takes JSON string as the parameter.
Return type: It returns the python dictionary object.
2. json.dumps()
Converts a Python object to a JSON string.
Syntax: json.dumps(object)
Parameter: It takes Python Object as the parameter.
Return type: It returns the JSON string.
3. update()
Updates a dictionary with elements from another dictionary or iterable key-value pairs.
Syntax: dict.update([other])
Parameters: Takes another dictionary or an iterable key/value pair.
Return type: Returns None.
Example 1: Updating a JSON string.
Python
import json
x = '{ "organization":"GeeksForGeeks","city":"Noida","country":"India"}'
# python object to be appended
y = {"pin":110096}
# parsing JSON string:
z = json.loads(x)
# appending the data
z.update(y)
# the result is a JSON string:
print(json.dumps(z))
Output:
{"organization": "GeeksForGeeks", "city": "Noida", "country": "India", "pin": 110096}
Example 2: Updating a JSON file.
The write_json() function reads the existing data, updates it, and then writes the updated data back to the file. Suppose the JSON file looks like this.

We want to add another JSON data after emp_details. Below is the implementation.
Python
import json
# Function to append new data to JSON file
def write_json(new_data, filename='data.json'):
with open(filename, 'r+') as file:
# Load existing data into a dictionary
file_data = json.load(file)
# Append new data to the 'emp_details' list
file_data["emp_details"].append(new_data)
# Move the cursor to the beginning of the file
file.seek(0)
# Write the updated data back to the file
json.dump(file_data, file, indent=4)
# New data to append
new_employee = {
"emp_name": "Nikhil",
"email": "[email protected]",
"job_profile": "Full Time"
}
# Call the function to append data
write_json(new_employee)
Output:
Similar Reads
Read JSON file using Python The full form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Pytho
4 min read
Reading and Writing JSON to a File in Python The full form of JSON is Javascript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Pytho
3 min read
How to Upload JSON File to Amazon DynamoDB using Python? Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. It offers scalability, reliability, and fast access to data for applications of any scale. DynamoDB supports both document and key-value data models and handles adminis
3 min read
Python - Dict of tuples to JSON In this article, we will discuss how to convert a dictionary of tuples to JSON. Method 1: Using json.dumps() This will convert dictionary of tuples to json Syntax: json.dumps(dictionary, indent) Parameters: Â dictionary is the input dictionary.indent specify the number of units of indentation Exampl
2 min read
Working With JSON Data in Python JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Python script. The tex
6 min read