Looking to extract specific key values from a nested JSON object based on the boolean value of another key. In this case, I need the "name" key values for items where the "checked" key is true, and return them in a result array.
Here is an example of the JSON structure:
const treeMetaData = [
{
name : 'database',
checked : true,
schemas : [
{
name : "schema1",
checked : true,
tables : [
{
name : "table1",
checked : true,
columns : [
{
name : "column1",
checked : false,
},
{
name : "column2",
checked : true,
}
]
},
]
},
{
name : "schema2",
checked : true,
tables : [
{
name : "table2",
checked : true,
columns : [
{
name : "column4",
checked : true,
},
{
name : "column5",
checked : false,
}
]
},
]
},
]
}]
The desired output based on the provided data:
["database", "schema1", "table1", "column2", "schema2", "table2", "column4"]
I am seeking an optimized approach as the treedata is quite large in size. Any help would be greatly appreciated.