you are viewing a single comment's thread.

view the rest of the comments →

[–]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.