Alkesh Mahajan Alkesh Mahajan - 24 days ago 9
JSON Question

How find data from JSON using python and watson discovery news

{
"matching_results": 1264,
"results": [
{
"main_image_url": "https://s4.reutersmedia.net/resources_v2/images/rcom-default.png",
"enriched_text": {
"entities": [
{
"relevance": 0.33,
"disambiguation": {
"subtype": [
"Country"
]
},
"sentiment": {
"score": 0
},
"type": "Location",
"count": 1,
"text": "China"
},
{
"relevance": 0.33,
"disambiguation": {
"subtype": [
"Country"
]
},
"sentiment": {
"score": 0
},


This is too much large file so I want to find "relevance" and "score" using python.

How fetch this info?

Answer Source

Regardless of how large it is, it is only a simple dictionary.

Iterate the lists. Extract the key-values.

for result in data['results']:
    for e in result['enriched_text']['entities']:
        print(e['relevance'])
        print(e['sentiment']['score'])