Extract values out of Array from JSON
Hi all,
I have an array from JSON which i get from text(response,result)
{ cost_per_km: 0.003, cost_per_mi: 0.004, 20_80_charge_Level1: “1:00”, 20_80_charge_Level2: “0:23”, 20_80_charge_Level3: “0:18” }
How do I extract the various values into individual fields? I have tried
let arr := text(response.result);
Cost_per_km := item(arr, 1) 
and
item(response.result, 3)
Thanks
7 replies
- 
  Hello, You have a JSON object not an array. Arrays are inside square brackets []. I“m not an expert with JSON, but it looks like the Ninox code editor does not like keys that start with numbers. I added quotes and didn”t get an error. let jsonObj := {cost_per_km: 0.003,cost_per_mi: 0.004,“20_80_charge_Level1”: “1:00”,“20_80_charge_Level2”: “0:23”,“20_80_charge_Level3”: “0:18”};jsonObj.“20_80_charge_Level2”You get the values from the object using dot notation. 
- 
  Thanks Sean, I get error though symbol expected at line 4 column 2, after the “ 
- 
  steergoosen, Some apects of the forum are fubared right now. The key names that start with 20_80 should be in single quotes. The forum is changing all single quotes to double quotes. 
- 
  Cool that works thanks - but at the risk of being blond (also my first time working with JSON, I was surprised I could do the GET working on my own) - how do I get the underlined dynamicaly? I tried let jsonObj := { “result”}. “Result” is a text field where the json GET result was printed to.let jsonObj := { 
 cost_per_km: 0.003,
 cost_per_mi: 0.004,
 “20_80_charge_Level1”: “1:00”,
 “20_80_charge_Level2”: “0:23”,
 “20_80_charge_Level3”: “0:18”
 };
- 
  I would try to use result as I get it and then store it in a Text field afterwards. If you store it in a Text field first, I think you’ll need to use the parseJSON() function on the value in the Text field to get the result. 
- 
  Wow, I just noticed the single quote wasn’t changed 
- 
  cool hehe 
Content aside
- 4 yrs agoLast active
- 7Replies
- 1267Views
