fix: mark decoded arrays with cjson array metatable#1
Conversation
📝 WalkthroughWalkthroughDecoder applies Changescjson Array Metatable Alignment
CI runner update
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the decoder so JSON arrays decoded via resty.simdjson are tagged with cjson.array_mt, making them round-trip correctly through cjson.encode (so [] doesn’t become {}), consistent with cjson.decode_array_with_array_mt(true) behavior.
Changes:
- Set
cjson.array_mton all decoded arrays in the Lua decoder. - Extend decode/empty-array tests to assert array metatables (including nested/empty arrays) and validate
cjson.encodeoutput.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/resty/simdjson/decoder.lua | Marks decoded arrays with cjson.array_mt during table construction. |
| t/02-decode.t | Adds assertions that decoded arrays (including nested arrays) have cjson.array_mt; asserts objects do not. |
| t/09-empty_array.t | Adds a regression test that cjson.encode preserves decoded empty arrays as []. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Luacheck Report1 tests 1 ✅ 0s ⏱️ Results for commit aa3816e. ♻️ This comment has been updated with latest results. |
Decoded JSON arrays now carry cjson.array_mt, matching cjson.decode_array_with_array_mt(true). This lets callers decode with simdjson and then encode with cjson without turning [] into {}.
This only changes simdjson decode output metadata. The simdjson encoder behavior is unchanged. The test workflow also moves from ubuntu-20.04 to ubuntu-latest because the old runner is no longer usable in this repo.
Tests run:
CI: