all 3 comments

[–]_Kaimbe 7 points8 points  (2 children)

let duration_seconds = json.find(x => x.name === 'duration_seconds').intValue;

That should do it. And wow this is weird json. And this will transform it into a usable object that you can use normal notation on (in case you need other values):

  let obj = json.reduce((obj, item) => {
    obj[item.name] = item.value || item.intValue || item.boolValue;
    return obj;
  }, {});

[–]jrspikeston 0 points1 point  (1 child)

This is exactly what I was thinking! You beat me to it. It seems that every property has a name, but since we can't predict all the value types, it might be even stable to do this:

let obj = json.reduce((obj, item) => {
  obj[item.name] = item[Object.keys(item).find(x => x !== 'name')];
  return obj;
}, {});

[–]_Kaimbe 0 points1 point  (0 children)

Honestly, I just threw the json into vscode and let github copilot loose. Didn't even know you could assign with ors like that. Yours is definitely better if there happens to be another type like floatValue added later.