async function jsonParser()

in contrib/html_demo/UICode/script.js [550:608]


async function jsonParser(jString, ovr) {
  let resp = JSON.parse(jString)
  if (Array.isArray(resp[0])) {
    if (resp[0][0].hasOwnProperty("top")) {
      // "[[top: #, ]]"
      // will need to target a different feature if another scenario ends up doing rectangle boxes
      for (let i in resp) {
        let j = i
        if (ovr) {
          j = ovr
        }
        await renderImage(j);
        for (let box of resp[i]) {
          let x = box.left
          let y = box.top
          let width = box.right - box.left
          let height = box.bottom - box.top
          let label = box.label_name
          imgdetection(j, x, y, width, height, label)
        }
      }
      return "detection"
    }
    return "err"
  }

  // '[{"label":"asdasd","probability":"0.21354"},{"label": "klsdfjkdsfjklsdf","probability":"0.4512457"}]'
  if(resp[0].hasOwnProperty("probability")) {
    for (let i in resp) {
      let j = i
      if (ovr) {
        j = ovr
      }
      await renderImage(j);
      let label = resp[i].label
      let prob = resp[i].probability
      imgclassification(j, label, prob);
    }
    return "classification"
  }

  if(resp[0].hasOwnProperty("features")) {
    for (let i in resp) {
      let j = i
      if (ovr) {
        j = ovr
      }
      await renderImage(j);
      let features = resp[i].features;

      // parse the json into an array
      let featuresArray = JSON.parse(features)

      imgsimilarity(j, 5, featuresArray);
    }
    return "similarity"
  }
  return "err"
}