LC8 - Stumbling into JSON

Sannyasin Brahmanathaswami brahma at
Mon Jun 13 18:30:34 EDT 2016

Not to trivialize the opacity of these things, but I used to resist JSON, but actually you can learn it in 10 minutes

It's actually much easier to grok in some ways than XML and now I prefer it to XML

Sure there are deeper, more complex levels, but at a very simple level:

This is json

fruitColors {
"oranges": "orange",

So LC will return this as an array

put fruitColors["apples']

# you will get value "red"

For this BMI calculator, that's all JSON you need to know.

returns a 2 dimensional array, 2  elements, each of which contains 2 elements


Graham wrote: "Where did the names ‘result’ and ‘value’ come from?"

They came from the first JSON name/value pair
Hope that helps


From: use-livecode <use-livecode-bounces at> on behalf of Graham Samuel <livfoss at>
Reply-To: How LiveCode <use-livecode at>
Date: Monday, June 13, 2016 at 12:08 PM
To: How LiveCode <use-livecode at>
Subject: LC8 - Stumbling into JSON

Sorry to be a pain, but again in the BMI example for LC 8 there is this function:

function getBMI pHeight, pWeight
    put "" &  "height_in_m=" & pHeight & "&weight_in_kg=" & pWeight into tURL
    put url tURL into tJSON
    put JsonImport(tJSON) into tArray
    return round(tArray["result"]["value"])
end getBMI

Knowing nothing about JSON, I find this confusing to say the least. I see that the JsonImport uses a URL to get some value(s) based on parameters incorporated in the URL, but what am I to make of the ‘return’ statement? I mean what do the bits in square brackets mean? Where did the names ‘result’ and ‘value’ come from? How would one know the spec of the result returned by a particular ‘JsonImport’ invocation? Are there libraries of these things, or what? How much JavaScript will I have to know to use this kind of functionality?

Feeling stupid.


use-livecode mailing list
use-livecode at<mailto:use-livecode at>
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

More information about the Use-livecode mailing list