Search code examples
jsonpython-3.xapigetrequest

Python Extract Value from Json


I Need to Exact Value from Json response

Json Response:

{
"data": {
"plot": "Rudy has always been told that he was too small to play college football. But he is determined to overcome the odds and fulfill his dream of playing for Notre Dame.",
"name": "Rudy",
"rating": "7.5",
"genre": "Biography,Drama,Sport",
"poster_url": "https://images-na.ssl-images-amazon.com/images/M/MV5BZGUzMDU1YmQtMzBkOS00MTNmLTg5ZDQtZjY5Njk4Njk2MmRlXkEyXkFqcGdeQXVyNjc1NTYyMjg@._V1_UY268_CR5,0,182,268_AL_.jpg" 
     }
}

Python Code:

response = requests.get(
    "http://theapache64.xyz:8080/movie_db/search?keyword=Titanic")
json_data = json.loads(response.text)

print(json_data["plot"])

Error:

KeyError: 'plot'

I need to extract "plot" value


Solution

  • plot is inside data:

    print(json_data['data']['plot'])