Skip to main content
Contents Index
Search Book
Search Results:
No results.
Read aloud
Readability settings Prev Up Next Scratch ActiveCode Profile
title here
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 15.5 What is JSON?
JSON stands for JavaScript Object Notation. It is a format for sharing data. You can read a JSON string from a file or from a URL and convert it into a Python dictionary or list. You can also convert a Python dictionary or list into a JSON string.
Subsection 15.5.1 Converting a JSON String into a Python Object
In the following program, we use the built-in
json library to parse the JSON string and return a Python list of dictionaries.
Activity 15.5.1 .
What do you think this code will print? Run it to see what it actually prints.
Activity 15.5.2 .
Here is another example. Run the code to see what it does.
Activity 15.5.3 .
What do you think this code will print? Run it to see what it actually prints.
Activity 15.5.4 .
Activity 15.5.5 .
Activity 15.5.6 .
Once you convert a JSON string to Python what are the two possible types for the Python object?
dictionary and string
Dictionaries are used in JSON, but strings only contain one element, so they are not as useful.
dictionary and list
JSON is constructed by nesting dictionaries and lists as needed.
string and list
Lists are used in JSON, but strings only contain one element, so they are not as useful.
Subsection 15.5.2 Converting a Python object into a JSON string
You can also convert a Python list or dictionary to a JSON string.
Activity 15.5.7 .
What do you think this code will print? Run it to see what it actually prints.
Activity 15.5.8 .
You have attempted
of
activities on this page.