DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

Posted on

Converting Python Dictionary to JSON string.

In this article you will learn how to convert python to json string.
The code below demonstrates it:

import json


person_dict =  {
    "name": "vincent", 
    "age" : 24,
    "profession":"software_Developer"
}

#converting  dictionary to json

person_json = json.dumps(person_dict)

print(person_dict)
Enter fullscreen mode Exit fullscreen mode

We import the json module, which provides functions for working with JSON data and json.dumps() function to convert the person_dict dictionary into a JSON string.
The json.dumps() function takes a Python object (in this case, the dictionary) and returns a JSON-formatted string representation of that object. In this code, the resulting JSON string is assigned to the variable person_json.

person_dict dictionary, displays the contents of the dictionary, showing the key-value pairs and their corresponding values.

output:{'name': 'vincent', 'age': 24, 'profession': 'software_Developer'}
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook