I am trying to get the filter result out from the json where the matched is true.
{
"cat": [
{
"volume": "one",
"category": [
{
"name": "Alpha",
"matched": true
},
{
"name": "Gamma",
"matched": false
}
]
},
{
"volume": "two",
"category": [
{
"name": "Beta",
"matched": false
},
{
"name": "Treta",
"matched": true
},
{
"name": "Neutral",
"matched": false
}
]
},
{
"volume": "three",
"category": [
{
"name": "Retro",
"matched": false
},
{
"name": "Jazz",
"matched": true
},
{
"name": "Rock",
"matched": false
},
{
"name": "Soft",
"matched": false
}
]
}
]
}
Used Javascript filter
var jsonwant = jsonusing.cat.filter(function(e){
return e.category.filter(function(e1){
return e1.matched === true;
});
});
Js Fiddle for same
Result Should Come as
"cat": [
{
"volume": "one",
"category": [
{
"name": "Alpha",
"matched": true
}
]
},
{
"volume": "two",
"category": [
{
"name": "Treta",
"matched": true
}
]
},
{
"volume": "three",
"category": [
{
"name": "Jazz",
"matched": true
}
]
}
]
but it is returning entire object.
e.category.filter(function(e1){ return e1.matched === true; });does what you want, but because that is being returned to the other filter it is keeping the entire object.{volume: "four", categories: []}? Or should that volume be excluded from the output?