Languages
[Edit]
EN

Python - convert string to json

0 points
Created by:
Antonina-Trejo
327

In this article, we would like to show you how to convert string to JSON in Python.

Quick solution:

import json

string = '{"id": 2, "name": "Tom", "age": 25}'
result = json.loads(string)

 

Practical example

In this example, we use json.loads() method to convert string to the JSON.

import json

string = '{"id": 2, "name": "Tom", "age": 25}'
result = json.loads(string)

print(result)
print(result["id"], result["name"], result["age"])

Output:

{'id': 2, 'name': 'Tom', 'age': 25}
2 Tom 25
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - convert string to json

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join