Erweiterung des JSON-Dokuments: Beauty and the Beast¶
In dieser Übung erweitere ich das JSON-Dokument des Films Beauty and the Beast um zwei Beispiel-Kommentare. Die Kommentare enthalten:
- Name des Benutzers
- E-Mail-Adresse des Benutzers
- Text des Kommentars
- Datum des Kommentars
Ursprüngliches JSON-Dokument¶
In [2]:
Copied!
movie = {
"id": 14253,
"Title": "Beauty and the Beast",
"year": 2016,
"language": "English",
"genre": "Romance",
"director": "Christophe Gans",
"runtime": 112,
"imdb": {
"rating": 6.4,
"votes": "17762"
},
"tomatoes": {
"viewer": {
"rating": 3.9,
"votes": 238
},
"critic": {
"rating": 4.2,
"votes": 8
},
"fresh": 96,
"rotten": 7
},
"comments": []
}
movie = {
"id": 14253,
"Title": "Beauty and the Beast",
"year": 2016,
"language": "English",
"genre": "Romance",
"director": "Christophe Gans",
"runtime": 112,
"imdb": {
"rating": 6.4,
"votes": "17762"
},
"tomatoes": {
"viewer": {
"rating": 3.9,
"votes": 238
},
"critic": {
"rating": 4.2,
"votes": 8
},
"fresh": 96,
"rotten": 7
},
"comments": []
}
Hinzufügen von Kommentaren¶
Ich füge zwei Beispiel-Kommentare zum JSON-Dokument hinzu. Die Kommentare enthalten:
- Name: "Talisa Maegyr", E-Mail: "oona_chaplin@gameofthron.es", Text und Datum.
- Name: "Melisandre", E-Mail: "carice_van_houten@gameofthron.es", Text und Datum.
Kommentare hinzufügen¶
In [3]:
Copied!
movie["comments"].append({
"name": "Talisa Maegyr",
"email": "oona_chaplin@gameofthron.es",
"text": "Rem itaque ad sit rem voluptatibus. Ad fugiat...",
"date": "1998-08-22T11:45:03.000+00:00"
})
movie["comments"].append({
"name": "Melisandre",
"email": "carice_van_houten@gameofthron.es",
"text": "Perspiciatis non debitis magnam. Voluptate...",
"date": "1974-06-22T07:31:47.000+00:00"
})
movie["comments"].append({
"name": "Talisa Maegyr",
"email": "oona_chaplin@gameofthron.es",
"text": "Rem itaque ad sit rem voluptatibus. Ad fugiat...",
"date": "1998-08-22T11:45:03.000+00:00"
})
movie["comments"].append({
"name": "Melisandre",
"email": "carice_van_houten@gameofthron.es",
"text": "Perspiciatis non debitis magnam. Voluptate...",
"date": "1974-06-22T07:31:47.000+00:00"
})
Erweiterte JSON-Dokument anzeigen¶
In [4]:
Copied!
import json
print(json.dumps(movie, indent=4))
import json
print(json.dumps(movie, indent=4))
{
"id": 14253,
"Title": "Beauty and the Beast",
"year": 2016,
"language": "English",
"genre": "Romance",
"director": "Christophe Gans",
"runtime": 112,
"imdb": {
"rating": 6.4,
"votes": "17762"
},
"tomatoes": {
"viewer": {
"rating": 3.9,
"votes": 238
},
"critic": {
"rating": 4.2,
"votes": 8
},
"fresh": 96,
"rotten": 7
},
"comments": [
{
"name": "Talisa Maegyr",
"email": "oona_chaplin@gameofthron.es",
"text": "Rem itaque ad sit rem voluptatibus. Ad fugiat...",
"date": "1998-08-22T11:45:03.000+00:00"
},
{
"name": "Melisandre",
"email": "carice_van_houten@gameofthron.es",
"text": "Perspiciatis non debitis magnam. Voluptate...",
"date": "1974-06-22T07:31:47.000+00:00"
}
]
}