Python - Dict of tuples to JSON Last Updated : 28 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Example: Python dict of tuples to json conversion Python3 # import json module import json # dictionary of employee data data = { "id": ("1", "2", "3"), "name": ("bhanu", "sivanagulu"), "department": ("HR", "IT") } # convert into json final = json.dumps(data, indent=2) # display print(final) Output: { "id": [ "1", "2", "3" ], "name": [ "bhanu", "sivanagulu" ], "department": [ "HR", "IT" ] }Method 2: Using json.dump() This will write converted json data into file, which will be downloaded and saved on your computer. Syntax: json.dump(dictionary,pointer) Parameters: dictionary is the input dictionary.pointer is the file pointer that is opened in write or append mode. Syntax: with open("mydata.json", "w") as final: json.dump(data, final) where, mydata is the new JSON file Finally , we have to download the created JSON file Syntax: files.download('mydata.json') Example: Python dict of tuples to json conversion Python3 # import json module from google.colab import files import json # dictionary of employee data data = { "id": ("1", "2", "3"), "name": ("bhanu", "sivanagulu"), "department": ("HR", "IT") } # convert into json # file name is mydata with open("mydata.json", "w") as final: json.dump(data, final) # download the json file files.download('mydata.json') Output: Comment More infoAdvertise with us Next Article Convert Tuple to List in Python G gottumukkala_sivanagulu Follow Improve Article Tags : Python Python-json Practice Tags : python Similar Reads Convert List Of Tuples To Json Python Working with data often involves converting between different formats, and JSON is a popular choice for data interchange due to its simplicity and readability. In Python, converting a list of tuples to JSON can be achieved through various approaches. In this article, we'll explore four different met 3 min read Convert Tuple to List in Python In Python, tuples and lists are commonly used data structures, but they have different properties:Tuples are immutable: their elements cannot be changed after creation.Lists are mutable: they support adding, removing, or changing elements.Sometimes, you may need to convert a tuple to a list for furt 2 min read Append to JSON file using Python 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. 2 min read Write a dictionary to a file in Python A dictionary store data using key-value pairs. Our task is that we need to save a dictionary to a file so that we can use it later, even after the program is closed. However, a dictionary cannot be directly written to a file. It must first be changed into a format that a file can store and read late 3 min read Python Tuples A tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogene 6 min read Python - Convert list of dictionaries to JSON Converting a list of dictionaries to JSON in Python involves serializing Python objects into a lightweight, human-readable JSON format used in APIs, storage and data exchange. For example, converting employee records stored as a list of dictionaries into a JSON structure allows easy data exchange or 3 min read Like