-
Notifications
You must be signed in to change notification settings - Fork 217
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
Problem with JSON encoding in lua #216
Comments
May not actually fix it now, just realised it was easier to monkey patch my lua code as follows:
|
Thank you for the issue and the potential workaround! I'll have a look soonish,
but it might take a bit thanks to summer and such.
|
I had a look, and you're right. But I don't see an easy enough way to fix this, without rewriting the whole encoding in gopher-json. JSON can only have strings as keys, so another workaround would be not to ask it to encode ints in the first place:
|
Thanks for having a look, performance aside, my monkey patching of the cjson.encode function in the lua scripts themselves is working ok, so I'm good. However, I have tried to study the code a bit, and it looks as though the implementation of the LTNumber case (https://github.com/alicebob/gopher-json/blob/master/json.go#L111) assumes that LTable.Next() will iterate an array in order. It looks very broken if this is not the case - so rather than switching on the key type, maybe we can switch on the key being the number 1, eg (not tested)
The the switch is done on the result of ClassifyTable(converted), and the case for NotArray (currently LTString) is extended to convert any numeric keys it finds to strings. |
Thanks for the extra effort. I don't think I'll dive into this. I'm happy to merge any PRs, esp if they are against the repo I forked (it had to be a fork to deal with some minor redis specific behavior). |
I only found out miniredis existed this morning and just wanted to say I think it is fantastic! However, I have hit a problem with json encoding in lua scripts. I have narrowed it down to the following example:
In redis 6.2.1 this ends up being encoded as a dictionary with the keys as strings, ie
However, it seems to result in
nil
using miniredis v2.15.1.I think I have managed to trace this to here: https://github.com/alicebob/gopher-json/blob/master/json.go#L111 where the code looks to be assuming that the presence of a number being returned as a table index means it is an array.
Hopefully I can fathom how to get the replace directive working in my go.mod and should be able to share an improvement to the existing code to at least fix this case if not fix it properly
The text was updated successfully, but these errors were encountered: