To work with nested JSON in Python, you can use the built-in json
module.
json
module:import json
json.loads()
or json.load()
method:data = '{"name": "John", "age": 30, "city": "New York", "skills": {"language": "Python", "database": "MySQL"}}'
python_obj = json.loads(data)
or
with open('data.json') as f:
python_obj = json.load(f)
print(python_obj['name']) # John
print(python_obj['skills']['language']) # Python
python_obj['skills']['database'] = 'PostgreSQL'
print(python_obj['skills']) # {'language': 'Python', 'database': 'PostgreSQL'}
json.dumps()
method:new_data = json.dumps(python_obj)
print(new_data)
OUTPUT:
{'name': 'John', 'age': 30, 'city': 'New York', 'skills': {'language': 'Python', 'database': 'PostgreSQL'}}
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-18 06:35:14 +0000
Seen: 12 times
Last updated: Jul 18 '23
What is the method to retrieve the JSON data from a column in SQL?
What is the process of developing two databases in a Django application using docker-compose?
How can a web application be developed to send distinct emails upon clicking the SUBMIT button?
What are the benefits of choosing sqlalchemy.types instead of sqlalchemy.dialects.mssql?
What is the method for placing parentheses in column names when creating a table using an SQL query?
Where does my Springboot application load its database from?
Can CakePHP be utilized with Oracle as the Database?
How can NVARCHAR be converted to VARCHAR?
How can Flask and SQLAlchemy be used to connect to a MySQL database?