{ "key1": "data", "key2": 27, "key3":
{ "key3_1": "something", "key3_2": "something
else" }, "key4":
[ "item1", "item2" ]}> We need to encode a LUA data structure using JSON encoding, but in a human readable format
On 28 September 2015 at 15:37, Bogdan Irimia <bog...@digitair.ro
<mailto:bog...@digitair.ro>> wrote:
> We need to encode a LUA data structureusing JSON encoding, but
in a human readable format
How about this:
https://github.com/bungle/lua-resty-libcjson
--
You received this message because you are subscribed to the Google
Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to openresty-en...@googlegroups.com
<mailto:openresty-en...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
print(json.encode({
key1 = "data",
key2 = 27,
key3 = {
key3_1 = "something",
key3_2 = "something else"
},
key4 = {
"item1",
"item2"
}
}, true)) {
"key1": "data",
"key3": {
"key3_1": "something",
"key3_2": "something else"
},
"key2": 27,
"key4": ["item1", "item2"]
}Not sure though if this is what you wanted as ut seems you like to have each array item on their own line.
Regards
Aapo
Monday, September 28, 2015 4:37 PM via Postbox
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
Monday, September 28, 2015 4:04 PM via Postbox
Wasn't clear for me if it formats the text as we need it.
Aapo Talvensaari wrote:
Monday, September 28, 2015 3:45 PM via Postbox> We need to encode a LUA data structure using JSON encoding, but in a human readable format
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
Monday, September 28, 2015 3:37 PM via Postbox
Hello, everybody
We need to encode a LUA data structure using JSON encoding, but in a human readable format, like this:
{"key1":"data","key2":27,
"key3": {"key3_1":"something","key3_2":"something else"},
"key4": ["item1","item2"]}
Please note the indentation for each item in the data structure.
I found for this two libraries written in pure Lua:
The first one seems to be faster for encoding (according to this: http://lua-users.org/wiki/JsonModules), but anyhow much slower than other C-based libraries (like "cjson" already included in OpenResty).
This type of "human readable encoding" (or "pretty encoding") is used only in a few places in our application, so performance is not critical, but the output has to be compatible with the "cjson" library.
What would you recommend?
Thank you
Bogdan
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
On Monday, 28 September 2015 16:39:05 UTC+3, bogdan wrote:
It'll do with arrays on one line. I tested it, works pretty ok for what we need