I am currently dealing with nested JSON files and looking to extract specific data from them. Here is an example of the JSON file I'm working with:
My goal is to identify all objects in the file where the value for "size" is equal to 1, and then add the corresponding "canonical" array from each object to a new array. In the provided example, this would result in an array containing 9 unique "canonical" arrays. So far, my attempts at achieving this using recursion have not been successful.
function recursive(json){
var arr = [];
if (json.size == 1) {
arr.push(json.canonical);
} else {
recursive(json.left);
}
return arr;
}
If anyone has suggestions or guidance on how to accomplish this task, I would greatly appreciate it. Thank you!