This topic contains 1 reply, has 1 voice, and was last updated by Eliot Muir 8 years, 11 months ago.
Easier way to create JSON with json.serialize
You must be logged in to reply to this topic.
This topic contains 1 reply, has 1 voice, and was last updated by Eliot Muir 8 years, 11 months ago.
One of the annoying things with our native json.serialize routine is that if you have a ‘userdata’ object – i.e. an HL7 or XML node tree inserted into the Lua table, the conversion code will choke and not convert it.
It’s bothered me for a while so as part of the rejig of the Channel Manager I implemented this wrapper function:
https://github.com/interfaceware/iguana-web-apps/blob/master/shared/json.lua
It iterates through the tree structure and finds userdata objects that support the nodeValue method and converts them into strings.
It works nicely so far, you can see how it simplifies the code:
https://github.com/interfaceware/iguana-web-apps/commit/43d4f34b9e10235f27c86d9a098e03abaacd1316#diff-46e8076ce53b54e012d15b66f8e05f55
Should be handy for anyone who is working on JSON in Iguana.
Here’s another nice example of simpler code:
https://github.com/interfaceware/iguana-web-apps/commit/1afccbbd4a8de6dd4770ccdc7892ca3364c82110
Hope people find it useful.
You must be logged in to reply to this topic.