Ajax-loader-large-white
How to use APIs with Python
Parsing JSON

JSON (which stands for JavaScript Object Notation) is an alternative to XML. It gets its name from the fact that its data format resembles JavaScript objects, and it is often more succinct than the equivalent XML. For instance, our same <pet> Jeffrey would look like this in JSON:

{
  "pets": {
    "name": "Jeffrey",
    "species": "Giraffe"
  }
}

Look, ma! No tags!

Instructions

Here we've imported the json module for parsing JSON, and we're using the open() method as before to read from pets.txt (under the "Files") tab. Reading from this file is just like reading JSON sent by a server. We've also imported the pprint function from the pprint module to use "pretty print" functionality that will print the output in a formatted way that's easier to read.

Click Save & Submit Code to continue!

?
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

The "u" appearing before each string in the output just means that they are unicode strings that might include special characters besides standard letters, numbers and symbols.

script.py
pets.txt