feat(json): add reviver support to GET, MGET, and ARRPOP#3205
Conversation
Allows passing an optional JSON.parse reviver function to transformReply. This enables automatic rehydration of types (like Dates) that are not natively supported by JSON. Modified: - JSON.GET: Added reviver to GetOptions - JSON.MGET: Added reviver to arguments - JSON.ARRPOP: Added reviver to ArrPopOptions - generic-transformers: Added reviver to transformRedisJsonReply and transformRedisJsonNullReply arguments Utilized .preserve to pass reviver through commands.
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
|
Hi @JeanSamGirard, thanks for the PR! I’d like 2 changes before merge:
After that, this looks good to merge. P.S. Its generally a good idea to open an issue before any work is done. This way you will make sure the feature is aligned and accepted by the maintainers beforehand, otherwise you are risking investing the time to implement something that could be rejected later. |
Hi, I made the fix for JSON.ARRPOP and added a test using a reviver for the 3 commands. (I'm not sure in which file the test for multi should go) Unfortunately it seems I'm unable to run them on my local for some reason... I'm on Windows 11 with docker desktop I keep getting "before all" hook for "client.json.get" I think the client isn't able to connect to the container. PS: Noted in the future I'll make an issue first ;) PPS: Sorry for all the additional commits, couldn't test locally so I had to trust 😅 |
|
Hi @nkaradzhov, wasn't sure if I should ping in my previous message. I ended up adding the multi() test case in packages\json\lib\commands\GET.spec.ts using multi().json.get for the test. If there's no other changes needed could you please approve so the tests can run? Thank you |
…into feat/json-reviver-support
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit d8f9d88. Configure here.
|
Hi @JeanSamGirard, so sorry for the delay, this somehow slipped. CI seems stuck, so im gonna close and reopen to force a new CI run |
…ead of the item, causing the test to fail
|
@nkaradzhov, Thank you ! Made the fix for the test that was failling, everything should be good now. |
Replace `res as any[]` cast with `res as Array<RedisJSON>` to satisfy @typescript-eslint/no-explicit-any lint rule. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Allows passing an optional JSON.parse reviver function to transformReply. This enables automatic rehydration of types (like Dates) that are not natively supported by JSON.
Modified:
Utilized .preserve to pass reviver through commands.
Description
I need to store arbitrary data structures in redis that may contain date objects or class instances that need to be rehydrated after being stringified, I believe others may have this need.
Commands that return JSON already needed to go through JSON.parse so this looked like a logical and easy feature to implement with the existing code structure. This is why I went ahead with making a pull request to add this feature myself instead of just creating an issue. (No linked issues)
PS: This is my first time contributing so if I'm doing anything wrong please tell me, thank you.
Checklist
npm testpass with this change (including linting)?Note
Low Risk
Additive, opt-in API on read paths only; default behavior unchanged when no reviver is passed.
Overview
Adds optional
JSON.parsereviver support when decoding JSON command replies, so callers can rehydrate values (e.g. strings back intoDate) after Redis returns plain JSON text.Shared helpers
transformRedisJsonReply/transformRedisJsonNullReplynow accept an optional reviver and export aJsonRevivertype. Commands stash the reviver onparser.preserve, matching how the client already passes the second argument intotransformReply(includingmulti().exec()).json.gettakesoptions.reviver;json.mGettakes an optional thirdreviverargument;json.arrPoptakesoptions.reviver.ARRPOPoptions typing is tightened sopath/indexare only valid together in the discriminated shape. Integration tests cover Date revival for these commands.Reviewed by Cursor Bugbot for commit af50332. Bugbot is set up for automated code reviews on this repo. Configure here.