Working with JSON

JSON, short for JavaScript Object Notation, is an open standard. Although its name doesn’t imply so, it is a language-independent data format. JSON can be used to both store and exchange data. It’s a prevalent data format because it is easy to read and write for humans too. Besides that, it has support for both dictionary-style data and arrays. It supports numbers, strings, booleans, and null (None in Python).

Python has two data types that, together, form the perfect tool for working with JSON: dictionaries and lists. Let’s explore how to:

  • load and write JSON
  • Pretty-print and validate JSON on the command line
  • Do advanced queries on JSON docs by using JMESPath