I'm trying to iterate through a JSON object I have, in order to retrieve a list of elements.
The JSON code I am sifting through is really complex, but here is small snippet. It basically shows what I'm looking for.
{ "ProductsList": [ { "ProductInfo": { "Brand": "LG", "p_product_barcode": "048231014731", "p_product_bullets_json": { "Value": [ "4.3 cubic foot ", "Recognized", "Customize your washer", "6Motion Technology ", "Troubleshoot quickly", "meow", "who", "special" ] } }] }
I'm trying to get the list of values from "Value", which is inside of "p_product_bullets_json". I want get all of the elements.
So far I have this, but all I'm getting is an empty list.
function getLists(obj, key) { // Empty object array var objects = []; // Searches through the JSON code to find the given key for (var k in obj) { // If there are still leafs left, then keep searching if (!obj.hasOwnProperty(k)) continue; // If the leaf doesn't match the key, try again (recursion) if (typeof obj[k] == 'object') { objects = objects.concat(getValues(obj[k], key)); // If the leaf does match the key, then push that value onto the array } else if (k == key) { $.each(obj[k], function(i, val) { console.log('Key: ' + i + ' Val: ' + val) }); } } return objects; }
I would just look through every Key for "Value", but this name isn't unique and there are other Key's with the same name in other places.
Any help would be greatly appreciated, thank you!
JSONhas already been parsed, sorry I probably should've made that clear. In my getLists function, it's calledobj. I was just showing an example of the thing I'm trying to find in my JSON.