I am new to Angualar js and json and frontend dev.so pls forgive my ignorance.I wanted to filter a json object based on a property:value. it doesn't contain arrays. and the property:value is always at the second level.its a hierarchical json not an array(parent->children->again children.). I have seen variants of the same question but most of them are dealing with array. below is my sample json.
{
"key1":
{
"prop11": "value11",
"prop2" : "N",
"prop13" : "value13"
},
"key2":
{
"prop21": "value21",
"prop2" : "Y",
"prop33" : "value23"
},
"key3":
{
"prop31": "value11",
"prop33" : "value13",
"prop2" : "N",
},
"key4":
{
"prop41": "value21",
"prop2" : "Y",
"prop43" : "value23"
},
.
.
.
.
}
I want to filter all children into a json object based on the value of prop2. that is, if prop2 : 'Y', then I want to add it to my final object.
Is this posible using angular js filter. I tried below sample but couldn't get desired results.
$filter('filter')(JSON.parse(jsonString),JSON.parse("{ \"Mandatory\":\"Y\"}"))
or
$filter('filter')(JSON.parse(jsonString),JSON.parse("{$:{Mandatory:'y'}}"))
or i tried to covert the sample json string to an array with single object by adding square bracket.
var array = '[ '+ jsonString + ' ]';
$filter('filter')(array,{$:{Mandatory:'y'}});
None of this worked.I am using the filter from the controller js file. Any help appreciated.