-1

I have this json file :

{
    "status": "OK",
    "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
    "url": "",
    "language": "english",
    "relations": [
        {
            "subject": {
                "text": "new single",
                "sentiment": {
                    "type": "positive",
                    "score": "0.179956"
                }
            },
            "action": {
                "text": "axed",
                "lemmatized": "axe",
                "verb": {
                    "text": "axe",
                    "tense": "past"
                }
            },

            "location": {
                "text": "in figure-hugging dress",
                "entities": [
                    {
                        "type": "City",
                        "text": "figure-hugging"
                    }
                ]
            }
        }
    ]
}

I want to get the sentiment type "positive" in the sentiment object within the subject object within the relations array what is the proper javascript code to locate this value ive tried

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0
var json = JSON.parse( ... your_loaded_json ... );

alert(json.relations[0].subject.sentiment.type);

Be mindful that you call JSON.parse on actual JSON. If this is just an object within your JavaScript script then simply:

var json = { ... your_object ... }

alert(json.relations[0].subject.sentiment.type);
shennan
  • 10,798
  • 5
  • 44
  • 79