JSON Files

This lesson focuses on JSON type files. It gives a complete explanation about how to read data from JSON files using the Pandas library of Python.

Introduction to JSON file #

JSON (JavaScript Object Notation) is a popular format allowing for a more flexible schema. It is also easy for humans to read and write. A lot of the data sent around the web is transmitted as JSON. Here is an example:

{
    "glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
}

Reading JSON file with Python #

Python can easily read these data from strings into dictionaries using the built-in json library:

Get hands-on with 1400+ tech skills courses.