json module
The Python standard library module that converts between Python values and JSON text.
In more detail
json.dumps turns a value into a JSON string and json.loads parses one back, while json.dump and json.load do the same with files. Dictionaries become objects, lists and tuples become arrays and None becomes null. Tuples come back as lists, dictionary keys become strings, and values such as sets and dates must be converted before saving.
Examples
json.dumps({"id": 42}).encode()import json
text = json.dumps({"a": [1, 2]}, indent=2)
json.loads(text)Related terms
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
- serialization — Turning an in-memory object into bytes, such as JSON text, that can be sent or stored, and parsing it back again.
- JSONDecodeError — The Python exception json.loads raises when the text it is given is not valid JSON.
- dictionary — A Python collection that stores values under keys, written in curly brackets, such as {"tea": 250}.
Taught in
- Retention Deletes Files, Not Records — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- The Field The Registry Refused — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Twelve Lines Instead Of Four Hundred — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- The New Broker That Did Nothing — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Duplicates Are The Default — Apache Kafka & Event Streaming
- Poison Messages And Dead Letter Topics — Apache Kafka & Event Streaming
- Bytes On The Wire: JSON, Avro And Protobuf — Apache Kafka & Event Streaming
- What A Program Really Is — Hands-on Python: Complete Video Course & Book
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Installing Python On Linux — Hands-on Python: Complete Video Course & Book
- JSON And CSV — Hands-on Python: Complete Video Course & Book