Skip to content

Add Lua-based cjson support #560

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

Closed
wants to merge 3 commits into from

Conversation

ivan-kripakov-m10
Copy link

@ivan-kripakov-m10 ivan-kripakov-m10 commented Nov 9, 2024

Partially closes #558

I tried several Lua-based Json libraries:

  1. http://dkolf.de/dkjson-lua/
  2. https://github.com/grafi-tt/lunajson
  3. https://github.com/rxi/json.lua
  4. https://github.com/harningt/luajson

My favorite is dkjson: it passes almost all test cases I prepared, lib has well-written documentation and great structure to add the configuration features support:
{ "encode_sparse_array", json_cfg_encode_sparse_array },
{ "encode_max_depth", json_cfg_encode_max_depth },
{ "decode_max_depth", json_cfg_decode_max_depth },
{ "encode_number_precision", json_cfg_encode_number_precision },
{ "encode_keep_buffer", json_cfg_encode_keep_buffer },
{ "encode_invalid_numbers", json_cfg_encode_invalid_numbers },
{ "decode_invalid_numbers", json_cfg_decode_invalid_numbers }

}

@TestTemplate
@Disabled("Failed to make dkjson return nil for null values")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will possibly require to make another one patch to dkjson sources

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limitation:

Frequently, in Lua, we assume that an array ends just before its first nil element. This convention has one drawback: We cannot have a nil inside an array.

}

@TestTemplate
@Disabled("Failed to make dkjson return correct value for string")
Copy link
Author

@ivan-kripakov-m10 ivan-kripakov-m10 Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will possibly require to make a patch to dkjson sources to support such behaviour

@ivan-kripakov-m10 ivan-kripakov-m10 changed the title Add Lua cjson support Add Lua-based cjson support Nov 9, 2024
@inponomarev
Copy link
Collaborator

Hi thanks for the PR!

Could you also try native Redis test cases for JSON https://github.com/redis/redis/blob/fdeb97629ef8964a5d9040328ee63734884ac874/tests/unit/scripting.tcl#L351 -- either by converting them to Java comparison tests or by running them directly from TCL (but I expect lots of other tests from scripting.tcl to fail, so maybe first option makes more sense)

@inponomarev inponomarev mentioned this pull request Nov 11, 2024
@ivan-kripakov-m10
Copy link
Author

closing in favor of #561

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lua cjson library
2 participants