JSON Basics and Parsing Data
2 min read ·
What is JSON
JSON stands for JavaScript Object Notation. It is a lightweight format used to store and exchange data.
It is:
- Text based
- Easy to read and write
- Widely used in APIs and web applications
json Module in Python
Python provides a built in module called
json to work with JSON data.JSON to Python Conversion using loads()
If you have JSON data in string format, you can convert it into Python object using
json.loads().Accessing Data from JSON
After converting JSON into Python, it becomes a dictionary.
Note
JSON objects are converted into Python dictionaries.
JSON Data Types to Python
When JSON is converted to Python, data types are mapped automatically.
- Object becomes dictionary
- Array becomes list
- String remains string
- Number becomes int or float
- true becomes True
- false becomes False
- null becomes None
Example with Multiple Data Types
Pro Tip
Always check type of parsed data using type() to understand structure.