Home > other >  parse nested JSON from vimeo API
parse nested JSON from vimeo API

Time:09-08

I set up a fiddle, with a simplified json response. I need to iterate over the json, and check for an object that has a metadata.connections.live_video.status of 'streaming'

I can't seem to access the property and values even when I'm just trying to console.log the number of instances it is looping through multiple times. Ultimately, I need to check for this status and pull the entire object out (store it as const) so I can access other properties of it that I didn't include - but again only if its metadata.connections.live_video.status = 'streaming'

$.each(json.body.data, function(key , value){ // First Level
    $.each(value.metadata.connections, function(ky , vl ){  // The contents inside data
     console.log(ky);
   });    
});

Thanks for the downvotes, you are awesome whoever you are

CodePudding user response:

https://jsfiddle.net/nrz3bu8y/

let data = json.body.data.filter(function(value, key) {
  let connection = value.metadata.connections['live_video'];
  return connection && connection.status === 'streaming';
})

You don't need to iterate connections, you know the key you're looking for. You also don't need to use jquery here, you're just working with vanilla javascript objects.

CodePudding user response:

It's because of how you're iterating over it. ky in your code is the key of the entry, vl will store the value of the object that you'll want to store

  • Related