Nearby lessons

103 of 108

Python - JSON Guide

What Is JSON?

JSON stands for JavaScript Object Notation and is a lightweight format for data exchange.

Why JSON Is Required

  • APIs
  • Web applications
  • Configuration files
  • System-to-system data exchange

json Module

Python provides the built-in json module.

import json

Converting Python to JSON

import json

student = {'name': 'Rahul', 'age': 25}
print(json.dumps(student))

Converting JSON to Python

import json

data = '{"name":"Rahul","age":25}'
print(json.loads(data))

JSON Files

Use json.load() to read from a file and json.dump() to write to a file.

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Python - Regular Expressions