Using json data from another field
Hi,
i want to use json data. For example:
var dist = @test;
dist.rows[0].elements[0].distance.value /1000
The json data look like that: {
"destination_addresses" : [ "Victoria, BC, Canada" ],
"origin_addresses" : [ "Seattle, Washington, États-Unis" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "297 km",
"value" : 296838
},
"duration" : {
"text" : "4 heures 48 minutes",
"value" : 17266
},
"status" : "OK"
}
]
}
],
"status" : "ha"
}
If i test directly with json data, i get what i want (distance value)
But replacing the data with @field (where the json data are stored) give me a "cannot read property '0' of undefined" error
Can you help on this please?
-
Very sorry for that! I check this before and found only thread about API. Maybe i didn't search correctly.
Here's the answer: https://help.podio.com/hc/communities/public/questions/202620823-Using-calulation-field-javascript-to-parse-JSONThanks a lot.
-
Hi Jean-Claude. So sorry, I totally ignored the other GF Forum Dimension we have.... As for GF, I am trying to go easy on my flows over there. Man, they add up so quickly. If it can be done in Podio, I'd rather save GF for mission-impossible.
Here it is for anyone who is interested in parsing Google Matrix JSON for distance and/or time between Point A and B. It works for me, Thanks Jean-Claude for starting this post.
try {
String(JSON.parse(@Distance JSON).rows[0].elements[0].distance.text);
} catch (e) {
"Could not parse JSON"
};I still cannot remove the word "ml" for miles after parsing the mileage number. :-(
Please sign in to leave a comment.
Comments
6 comments