I have the following JSON records
{
"data": {
"content": "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan stand-out skill,but he still holds a defensive NBA record, with eight steals in a half.",
"knowledge": [
{
"label": "action",
"properties": [
{
"type": "WikiDataId",
"value": "Q522344"
}
],
"syncon": 628
},
{
"label": "quality.human_feature",
"properties": [
{
"type": "WikiDataId",
"value": "Q205961"
}
],
"syncon": 25683
},
{
"label": "person.basketball_player",
"properties": [
{
"type": "WikiDataId",
"value": "Q3665646"
}
],
"syncon": 41583
},
{
"label": "object_group.property",
"syncon": 54375
},
{
"label": "other",
"syncon": 86973
},
{
"label": "event.happening",
"syncon": 111950
},
{
"label": "other",
"syncon": 160458
}
],
"language": "en",
"sentiment": {
"items": [
{
"items": [
{
"lemma": "but",
"sentiment": -1.0,
"syncon": 160458
},
{
"lemma": "stand-out",
"sentiment": 0.0,
"syncon": 111950
},
{
"lemma": "skill",
"sentiment": 9.5,
"syncon": 25683
},
{
"lemma": "steal",
"sentiment": 6.0,
"syncon": 54375
}
],
"lemma": "",
"sentiment": 7.19,
"syncon": -1
},
{
"items": [
{
"lemma": "scoring",
"sentiment": 3.5,
"syncon": 628
}
],
"lemma": "Michael Jordan",
"sentiment": 3.5,
"syncon": -1
},
{
"items": [
{
"lemma": "good",
"sentiment": 5.0,
"syncon": 86973
}
],
"lemma": "basketball player",
"sentiment": 5.0,
"syncon": 41583
}
],
"negativity": 0.0,
"overall": 14.19,
"positivity": 14.19
},
"version": "sensei: 3.3.2; disambiguator: 15.0-QNTX-2016"
},
"success": true
}
I was able to get the value of content successfully.
Now I want to get values for each lemma and sentiment, overall and negativity. How can I achieve that?
Below is my coding so far.
<?php
$output='
{"data":{"content":"Michael Jordan was one of the best basketball players of all time. Scoring was Jordan stand-out skill,but he still holds a defensive NBA record, with eight steals in a half.","knowledge":[{"label":"action","properties":[{"type":"WikiDataId","value":"Q522344"}],"syncon":628},{"label":"quality.human_feature","properties":[{"type":"WikiDataId","value":"Q205961"}],"syncon":25683},{"label":"person.basketball_player","properties":[{"type":"WikiDataId","value":"Q3665646"}],"syncon":41583},{"label":"object_group.property","syncon":54375},{"label":"other","syncon":86973},{"label":"event.happening","syncon":111950},{"label":"other","syncon":160458}],"language":"en","sentiment":{"items":[{"items":[{"lemma":"but","sentiment":-1.0,"syncon":160458},{"lemma":"stand-out","sentiment":0.0,"syncon":111950},{"lemma":"skill","sentiment":9.5,"syncon":25683},{"lemma":"steal","sentiment":6.0,"syncon":54375}],"lemma":"","sentiment":7.19,"syncon":-1},{"items":[{"lemma":"scoring","sentiment":3.5,"syncon":628}],"lemma":"Michael Jordan","sentiment":3.5,"syncon":-1},{"items":[{"lemma":"good","sentiment":5.0,"syncon":86973}],"lemma":"basketball player","sentiment":5.0,"syncon":41583}],"negativity":0.0,"overall":14.19,"positivity":14.19},"version":"sensei: 3.3.2; disambiguator: 15.0-QNTX-2016"},"success":true}
';
echo $output;
echo "<br><br>";
$json= json_decode($output, true);
foreach($json as $v1){
echo $content = $v1['content'];
echo "<br><br>";
/*
foreach($json as $v1['items']){
echo $lemma = $v1['items']['lemma'];
echo $sentiment = $v1['items']['sentiment'];
}
echo $negativity = $v1['negativity'];
echo $overall = $v1['overall'];
*/
}
?>