Skip to content

Instantly share code, notes, and snippets.

import json
with open('bookstore.json', 'r') as f:
bookstore_dict = json.load(f)
print(bookstore_dict['bookstore']['book'][0]['_category'])
import json
with open('bookstore.json', 'r') as f:
bookstore_dict = json.load(f)
print(bookstore_dict['bookstore']['book'][0]['price'])
{
"bookstore": {
"book": [
{
"title": {
"_lang": "en",
"__text": "Everyday Italian"
},
"author": "Giada De Laurentiis",
"year": "2005",
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
{
"bookstore": {
"book": [
{
"title": {
"_lang": "en",
"__text": "Everyday Italian"
},
"author": "Giada De Laurentiis",
"year": "2005",
{
"breakfast_menu": {
"food": [
{
"name": "Belgian Waffles"
"price": "$5.95",
"description": "Two of our famous Belgian Waffles with plenty of real maple syrup",
"calories": "650"
},
{