Redis Lua Differentiating Empty Array and Object

I ran into this error in cjson lua when I used a script in redis 3.2 to set a specific value in a json object.

Currently lua in redis does not distinguish between empty json array or empty json object. This causes serious problems when serializing json objects with arrays inside them.

eval "local json_str = '{\"items\":[],\"properties\":{}}' return cjson.encode(cjson.decode(json_str))" 0

      

Result:

"{\"items\":{},\"properties\":{}}"

      

I found this solution https://github.com/mpx/lua-cjson/issues/11 but I was unable to implement it in the redis script.

This is a failed attempt:

eval 

"function cjson.mark_as_array(t) 
local mt = getmetatable(t) or {} 
mt.__is_cjson_array = true 
return setmetatable(t, mt) 
end 
function cjson.is_marked_as_array(t) 
local mt = getmetatable(t) 
return mt and mt.__is_cjson_array end 
local json_str = '{\"items\":[],\"properties\":{}}' 
return cjson.encode(cjson.decode(json_str))" 

0

      

Any help or pointer is appreciated.

+3
json lua redis cjson


source to share


No one has answered this question yet

Check out similar questions:

2633
How do I check for an empty JavaScript object?
1567
Converting form data to JavaScript object with jQuery
1317
Memcached vs. Redis?
1158
Safely converting a JSON string into an object
672
How do I remove everything in Redis?
525
How to atomically delete keys matching a pattern using Redis
4
Lua to Redis from JSON
2
HGETALL returns an array instead of a hash when using lua scripts [Rails, Redis, Lua]
1
How to insert key value object into lua table inside redis
0
cjson decode in Lua returns an array of empty arrays redis-cli



All Articles
Loading...
X
Show
Funny
Dev
Pics