feat(json): add reviver support to GET, MGET, and ARRPOP by JeanSamGirard · Pull Request #3205 · redis/node-redis

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.

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

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Medium Risk
Expands the public API and changes reply parsing for several JSON commands by threading a user-provided JSON.parse reviver through parser.preserve, which could affect downstream typing/behavior and has some risk of subtle parsing differences.

Overview
Adds optional JSON.parse reviver support for JSON module replies so callers can rehydrate types (e.g., Dates) when decoding RedisJSON strings.

This threads a reviver function through parser.preserve and updates transformRedisJsonReply/transformRedisJsonNullReply plus JSON.GET, JSON.MGET, and JSON.ARRPOP to pass the reviver into reply transformation; includes new tests covering reviver behavior and null/multi-key cases.

Written by Cursor Bugbot for commit ed7aa40. This will update automatically on new commits. Configure here.