Using JSON to store data in variable

I want to parse JSON. Can someone please help me?

I have to open this URL to get the response:
http://192.168.1.23/get/data/1

{"value":"1","key":"D13","response":"get"}
In this case I want to make a variable D13 with the value 1.

Thanks for any help.

Any examples, anything?

There are many implementations of JSON encoders/decoders. There’s probably one on your system already if you have certain plugins installed. It’s usually just a matter of accessing the module and calling its decode function.

local json = require "json" -- actual text depends on installed json module

local result = json.decode(json_string)

Going the other way is just as easy:

local json_string = json.encode(result)

The [tt]result[/tt] contains the decoded table structure of the given json string.

I’ll add a link to a module, but if you have dataMine installed, then it has one called [tt]json-dm[/tt].

[Edit : here’s one I wrote earlier: [url=http://forum.micasaverde.com/index.php/topic,17499.msg137677.html#msg137677]http://forum.micasaverde.com/index.php/topic,17499.msg137677.html#msg137677[/url] ]