You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cjson.encode can not have the fixed order since Lua table doesn't have a fixed order for keys.
otherwise, cjson.encode have to sort for the keys, it will hit bad performance then.
There is a PR on the original mpx/lua-cjson repo here, that adds support for this. It only took a few small tweaks to get working with the latest openresty/lua-cjson. I have a working branch of this here.
Just configure OpenResty with the --without-lua_cjson flag, and then you can just build and require your own custom cjson (I'm using LuaRocks for this) in your project. I've been using this in production for almost a year with no problems. Performance is still great.
There is a PR on the original mpx/lua-cjson repo here, that adds support for this. It only took a few small tweaks to get working with the latest openresty/lua-cjson. I have a working branch of this here.
Just configure OpenResty with the --without-lua_cjson flag, and then you can just build and require your own custom cjson (I'm using LuaRocks for this) in your project. I've been using this in production for almost a year with no problems. Performance is still great.
This is a good method, but it seems that it can only be applied to a small amount of data. The number of citations Lua stack is limited to 20
Activity
dannygueta commentedon Mar 1, 2021
Hi,
same problem here, any lead ?
Thanks.
libing0526 commentedon Sep 10, 2021
I hava the same problem,anybody knows why?
doujiang24 commentedon Sep 10, 2021
cjson.encodecan not have the fixed order since Lua table doesn't have a fixed order for keys.otherwise,
cjson.encodehave to sort for the keys, it will hit bad performance then.travisbell commentedon Sep 10, 2021
There is a PR on the original mpx/lua-cjson repo here, that adds support for this. It only took a few small tweaks to get working with the latest openresty/lua-cjson. I have a working branch of this here.
Just configure OpenResty with the
--without-lua_cjsonflag, and then you can just build and require your own custom cjson (I'm using LuaRocks for this) in your project. I've been using this in production for almost a year with no problems. Performance is still great.libing0526 commentedon Sep 13, 2021
This is a good method, but it seems that it can only be applied to a small amount of data. The number of citations Lua stack is limited to 20
libing0526 commentedon Sep 24, 2021
https://plain.blog.csdn.net/article/details/120364853
it seems like a good method
edo888 commentedon Apr 16, 2022
You can possibly define the order you want in __order metatable and use the forked version: https://github.com/edo888/lua-cjson
Output:
{"name":"yhc","age":40,"birthday":"1985"}feature: add option to sort encoded object keys
feature: add option to sort encoded object keys