🎓 All Courses | 📚 Python Programming Syllabus

📋 Study this course on TaskLoco
#python-programming#json#data

JSON — Python's Native Data Exchange Format

Python's json module makes JSON trivial.


Parse JSON string to Python dict:

import json

json_string = '{"name": "Alice", "age": 30}'
data = json.loads(json_string)
print(data["name"])  # Alice

Convert Python dict to JSON string:

data = {"name": "Alice", "scores": [95, 87, 92]}
json_string = json.dumps(data, indent=2)
print(json_string)

Read JSON from file:

with open("data.json", "r") as f:
    data = json.load(f)

Write JSON to file:

with open("output.json", "w") as f:
    json.dump(data, f, indent=2)

Type mapping:

JSON object → Python dict

JSON array → Python list

JSON string → Python str

JSON number → Python int or float

JSON true/false → Python True/False

JSON null → Python None


YouTube • Top 10
Python Programming: Working with JSON
Tap to Watch ›
📸
Google Images • Top 10
Python Programming: Working with JSON
Tap to View ›

Reference:

Wikipedia: JSON

image for linkhttps://en.wikipedia.org/wiki/JSON

📚 Python Programming — Full Course Syllabus
📋 Study this course on TaskLoco

TaskLoco™ — The Sticky Note GOAT