How to extract specific text from JSON response

Question:

I am using the Twitter API to source tweets, and am using their provided GitHub example. However, the tweets are given in a JSON format. How can I extract one part (specifically the text and tag) and place it into either a list, dataframe (most ideal option), dict etc?

    for response_line in response.iter_lines():
    if response_line:
        json_response = json.loads(response_line)
        tweets.append(json_response)

Upon viewing the ‘tweets’ list, the data uses the following format:

{'data': {'id': '1562362833374945281',
'text': 'Waiting  ......'},
'matching_rules': [{'id': '1562362617708027906', 'tag': 'bitcoin'}]}
Asked By: Max Allen

||

Answers:

json.loads() returns a dictionary. So e.g. to get the text:

json_response = json.loads(response_line)
text = json_response.get("data").get("text")
Answered By: Peter Dekkers
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.