Skip to content
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

feat: encode sparse lua arrays as json map (object) #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

HannesLueer
Copy link

With my suggestion it is possible to represent sparse arrays from lua in a useful way in JSON by representing them as a map. Therefore I use the index of the lua array as key in the JSON map.

Lua:

{
  1,
  2,
  [10] = 3
}

=> JSON

{
  "1": 1,
  "10": 3,
  "2": 2
}

If there are no holes in the lua array, a normal JSON array will still be output:

Lua: {1, 2, 3, 4, 5}
JSON: [1, 2, 3, 4, 5]

In contrast to the pull request #12, the index/key can be usefully processed further and easily retrieved.

hbagdi and others added 8 commits December 3, 2021 09:14
Certain Kong error message are in the following format which indicate
index value for error in an array:

```
errors = {
  config = {
    response_if_status_code = {
      [2] = "value should be between 100 and 599"
    }
  }
}
```

This fix allows for sparse array and converts the key (which is the
index in this case) into part of the error message.

* test: add a test for UserData removal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants