How to use json.dumps() In Python

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"
  ]
}

Python – Dict of tuples to JSON

In this article, we will discuss how to convert a dictionary of tuples to JSON.

Similar Reads

Method 1: Using json.dumps()

This will convert dictionary of tuples to json...

Method 2: Using json.dump()

...