-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: encoding empty array #1
Comments
Okay, I think I have fixed this now. Example code: local json = require "cjson"
print(json.decode("[]").__jsontype) -- "array"
-- you could also check it like this:
print(getmetatable(json.decode("[]")) == json.object) -- false
print(getmetatable(json.decode("[]")) == json.array) -- true
-- or
print(json.decode("[]").__jsontype == "object") -- false
print(json.decode("[]").__jsontype == "array") -- true
print(json.decode("{}").__jsontype) -- "object"
print(json.encode(setmetatable(json.decode("[]"), json.object))) -- {}
print(json.encode(setmetatable(json.decode("{}"), json.array))) -- []
print(json.encode(json.decode("[]"))) -- []
print(json.encode(json.decode("{}"))) -- {} Was this what you were looking for?
And you are welcomed to reopen this issue, if you feel like it was not resolved. Regards |
good works. |
thanks! |
Would be nice to be able to set a flag to force a empty table to be
encoded as an array []
Also mentioned here: mpx/lua-cjson#11
and here: http://openmymind.net/Lua-JSON-turns-empty-arrays-into-empty-hashes/
The text was updated successfully, but these errors were encountered: