VOOZH about

URL: https://www.geeksforgeeks.org/python/python-convert-json-to-string/

⇱ Convert JSON to string - Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert JSON to string - Python

Last Updated : 12 Jul, 2025

Data is transmitted across platforms using API calls. Data is mostly retrieved in JSON format. We can convert the obtained JSON data into String data for the ease of storing and working with it. Python provides built-in support for working with JSON through the json module. We can convert JSON data into a string using the json.dumps() method.

Let's see how to convert JSON to String.

Json to String on dummy data using "json.dumps"

This code creates a Python dictionary and converts it into a JSON string using json.dumps(). The result is printed along with its type, confirming that the output is now a string.

Output: 

👁 jsonToString

Explanation:

  • json.dumps(a) converts the dictionary a into a JSON-formatted string.
  • print(y) prints the JSON string.
  • print(type(y)) prints the type of the variable y, which will be <class 'str'> since the JSON data is now a string.

Json to String using an API using requests and "json.dumps"

This code makes a GET request to a dummy API to fetch employee data, converts the JSON response into a Python dictionary using json.loads(), and then converts it back into a JSON string using json.dumps(). The string is printed along with its type.

Output: 

👁 Image

Explanation:

  • requests.get() fetches data from the API.
  • json.loads(res.text) converts the JSON string to a dictionary.
  • json.dumps(d) converts the dictionary back to a JSON string.
Comment