Given the following list of tuples, write Python code to parse the id, name, and age from each JSON string.
1Times asked
Sep 2026Last seen
Sep 2026First seen
💡 Model Answer
You can use the json module to load each JSON string and then extract the fields. Here’s a concise solution:
python
import json
data = [
(1, '{"name":"John","age":30,"address":{"city":"Bangalore","country":"India"}}'),
(2, '{"name":"Alice","age":25,"address":{"city":"Mumbai","country":"India"}}'),
(3, '{"name":"Bob","age":35,"address":{"city":"Delhi","country":"India"}}')
]
for record_id, json_str in data:
obj = json.loads(json_str)
name = obj.get('name')
age = obj.get('age')
print(f'id={record_id}, name={name}, age={age}')Output:
id=1, name=John, age=30
id=2, name=Alice, age=25
id=3, name=Bob, age=35The time complexity is O(n) where n is the number of tuples, and the space complexity is O(1) aside from the input list.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500