Languages
[Edit]
EN

Python - convert string to json

0 points
Created by:
Antonina-Trejo
237

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

Python - string (popular problems)

Python - 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