0Pricing
Python Academy · Lesson

JSON Encoding and Decoding

Use json.loads, json.dumps, and json.load/dump for JSON I/O.

Introduction

Python's json module converts between Python objects and JSON strings or files with simple, consistent functions.

json.dumps()

json.dumps(obj) serializes a Python object to a JSON string. indent=2 pretty-prints it.
import json
d = {'name': 'Alice', 'age': 30, 'active': True}
print(json.dumps(d, indent=2))

All lessons in this course

  1. JSON Encoding and Decoding
  2. Handling Nested JSON Structures
  3. Reading CSV with csv.reader
  4. Writing CSV with csv.DictWriter
← Back to Python Academy