ChatGPT writes custom widgets

Hey All,

An internal user came to me asking for a good way to extract values out of JSON text. They wanted to be able to use dot-notation to extract any key from a json from within an app.

Out of curiosity I asked my new best friend and it helped me out…


The last step was to connect the wires to Tulip, and I came to this:

    getJsonValue(getValue("Json Object"),getValue("Json extractor"));
});
getValue('Json extractor', (internalVariable) => {    
    getJsonValue(getValue("Json Object"),getValue("Json extractor"));
});



function getJsonValue(string, extractor) {
    const jsonObject = JSON.parse(string)
    if (jsonObject ==null || extractor == null){
        return null
    }
  let keys = extractor.split('.');
  let value = jsonObject;
  for (let i = 0; i < keys.length; i++) {
    if (value.hasOwnProperty(keys[i])) {
      value = value[keys[i]];
    } else {
      return null;
    }
  }
  console.log(value)
  setValue("Output",value.toString());
  return value;
}

Works like a charm! Starting to wonder where else within Tulip we could leverage ChatGPT-
Pete

customWidget-Json Parse To Text.json (2.7 KB)

6 Likes

I want to see what everyone is doing here!

A few weekends ago I used chatGPT to help me create a garden planning app in Tulip. It gave me a grid off square feet, and helped me get assign each square an index. Goal is to pass a vegetable/color object pulled from table data into each square foot and track from there.

2 Likes