Pkeod
April 21, 2016, 11:03am
1
There is json.decode - I think a built in json.encode would be useful and logical.
There are other already made ways to do it but I think if json.decode exists so should json.encode for turning a lua table into JSON as a part of core api.
json.lua
--[[ json.lua
A compact pure-Lua JSON library.
The main functions are: json.stringify, json.parse.
## json.stringify:
This expects the following to be true of any tables being encoded:
* They only have string or number keys. Number keys must be represented as
strings in json; this is part of the json spec.
This file has been truncated. show original
http://regex.info/blog/lua/json
http://lua-users.org/wiki/JsonModules
6 Likes
jeevan
November 24, 2016, 6:13pm
2
A json.encode would be great, I was surprised there is only a decode
@Pkeod Thanks for the Gist, I’m using it in my project now and it seems to work well.
jeevan
November 24, 2016, 7:21pm
4
Thanks again @Pkeod . Switched to the Playfab one (and its also working).
endel
July 12, 2018, 8:25pm
5
is there a reason why json.encode()
is not available in the official API?
britzl
July 12, 2018, 9:15pm
6
Yes, a semi vague reason. Should an empty table encode to a JSON object {} or an array []?
This is my goto solution for json.encode: https://github.com/rxi/json.lua
2 Likes