Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Working with JSON | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 23 of 55

·Python

Working with JSON

20 minutes

Course progress42%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • `json.dumps(obj)` converts a Python object to a JSON string.
  • `json.loads(str)` parses a JSON string back to a Python object.
  • `json.dump(obj, file)` writes JSON to a file; `json.load(file)` reads it.
  • Supported types: dict, list, str, int, float, bool, None.

Working with JSON

JSON (JavaScript Object Notation) is a lightweight data‑exchange format. Python’s json module makes converting between JSON strings and native objects effortless.

import json

# Serialize a Python dict to JSON
data = {'name': 'Alice', 'age': 30}
json_str = json.dumps(data)
print('JSON:', json_str)

# Deserialize back to a dict
loaded = json.loads(json_str)
print('Name from JSON:', loaded['name'])

When working with files, use json.dump() and json.load() to read/write directly.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonImporting Standard LibraryContinue to lesson 24Regular ExpressionsBack to Python Fundamentals curriculum