Skip to content

feat: JSON.MERGE plus unit and integration tests - #95

Merged
roshkhatri merged 23 commits into
valkey-io:unstablefrom
patrickn2:feat--JSON.MERGE-Command
Jul 1, 2026
Merged

feat: JSON.MERGE plus unit and integration tests#95
roshkhatri merged 23 commits into
valkey-io:unstablefrom
patrickn2:feat--JSON.MERGE-Command

Conversation

@patrickn2

@patrickn2 patrickn2 commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

JSON.MERGE Command
Followed instructions here https://redis.io/docs/latest/commands/json.merge/

Closes #74.

@patrickn2 patrickn2 mentioned this pull request Dec 30, 2025
@roshkhatri

roshkhatri commented Dec 30, 2025

Copy link
Copy Markdown
Member

Can you please add --sign off to the commits?: https://github.com/valkey-io/valkey-json/pull/95/checks?check_run_id=59176701849

@patrickn2

Copy link
Copy Markdown
Contributor Author

Can you please add --sign off to the commits?: https://github.com/valkey-io/valkey-json/pull/95/checks?check_run_id=59176701849

I guess I made a mess trying to fix it
Could you take a look?

@roshkhatri

Copy link
Copy Markdown
Member

Can you please add --sign off to the commits?: https://github.com/valkey-io/valkey-json/pull/95/checks?check_run_id=59176701849

I guess I made a mess trying to fix it Could you take a look?

Yeah, its okay , you can just run these commands and it should be fine:

git rebase HEAD~3 --signoff
git push --force-with-lease origin feat--JSON.MERGE-Command

@patrickn2
patrickn2 force-pushed the feat--JSON.MERGE-Command branch from 9301a02 to 3bb9a5d Compare December 30, 2025 22:18
@patrickn2

Copy link
Copy Markdown
Contributor Author

Can you please add --sign off to the commits?: https://github.com/valkey-io/valkey-json/pull/95/checks?check_run_id=59176701849

I guess I made a mess trying to fix it Could you take a look?

Yeah, its okay , you can just run these commands and it should be fine:

git rebase HEAD~3 --signoff
git push --force-with-lease origin feat--JSON.MERGE-Command

Done

@roshkhatri roshkhatri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, just some suggestions and may need to add more tests

Comment thread src/json/dom.cc Outdated
Comment thread src/json/json.cc Outdated
Comment thread src/json/dom.cc
Comment thread CMakeLists.txt
Comment thread build.sh
Comment thread tst/integration/test_json_basic.py
Comment thread tst/integration/conftest.py
Comment thread docs/JSON.MERGE_COMPLEXITY.md Outdated
Comment thread docs/JSON.MERGE_SUMMARY.md Outdated
Comment thread docs/JSON.MERGE_SUMMARY.md Outdated
@patrickn2
patrickn2 force-pushed the feat--JSON.MERGE-Command branch 2 times, most recently from b53bf08 to 9713e53 Compare January 6, 2026 14:37
@roshkhatri

Copy link
Copy Markdown
Member

The failing CI would be fixed once we merge the latest unstable into this branch

@roshkhatri

Copy link
Copy Markdown
Member

I am not sure though why these are failing: https://github.com/valkey-io/valkey-json/actions/runs/20278225578/job/58232842208
here the cloning into valkey is working but on this PR there seems to be some issue

Comment thread src/CMakeLists.txt Outdated

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments from my end. Thank you for the change.

Comment thread src/json/dom.cc Outdated
Comment thread src/json/dom.cc Outdated
Comment thread src/json/dom.cc Outdated
Comment thread src/json/json.cc Outdated
Comment thread src/json/dom.cc Outdated
@patrickn2
patrickn2 force-pushed the feat--JSON.MERGE-Command branch 2 times, most recently from c8376e8 to c62cd5a Compare February 6, 2026 21:35
@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

@patrickn2 thanks for the fixes. Allow me some time to review again!

Comment thread .github/workflows/ci.yml

@mkmkme mkmkme left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Here are some opinionated drive-by comments on the PR. Could you have a look please?

Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml
Comment thread src/json/dom.cc
Comment thread src/json/dom.cc Outdated
Comment thread src/json/dom.cc Outdated
Comment thread src/json/dom.cc Outdated
Comment thread src/CMakeLists.txt
Comment thread build.sh
Comment thread CMakeLists.txt Outdated

@roshkhatri roshkhatri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont have more to add to what @sarthakaggarwal97 and @mkmkme
I think just rebasing onto unstable should work

Comment thread .github/workflows/ci.yml
Comment thread tst/integration/conftest.py
@roshkhatri

Copy link
Copy Markdown
Member

@patrickn2, if possible, can you please take a look at the feedback?
Valkey will be releasing 9.1 rc1 soon and we can release new version for valkey-json, so we can have valkey-json in the next bundle release.

@patrickn2

Copy link
Copy Markdown
Contributor Author

I guess I fixed everything guys
Thank you for your review @mkmkme @roshkhatri

@patrickn2
patrickn2 force-pushed the feat--JSON.MERGE-Command branch from c8e2180 to bdbf4b4 Compare March 6, 2026 13:26
Comment thread build.sh Outdated
…ck Nogueira <patricknn@gmail.com>

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…it and add unit tests for depth limit scenarios

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…d improve memory tracking. Update unit tests for merge values.

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…ses, and add unit tests for various merge scenarios

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…ts for various merge scenarios including array and object replacements

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…, mixed updates, error handling, and no-op scenarios

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
- Introduced a new configuration key `json.max-path-limit` to set the maximum nesting depth for JSON documents.
- Updated README.md to include details about the new configuration option, its default value, and usage instructions.
- Modified merge_values function to ensure proper handling of empty objects during merging.
- Adjusted the command info for JSON.MERGE to reflect a new parameter value.

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…fixed them

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…nd add a new unit test for object replacement in merging

- Moved the check for empty objects in merge_values to ensure proper handling during merging.
- Added a unit test to verify that an object replaces an array at a specified key in the merge process.

Signed-off-by: patricknn@gmail.com <patricknn@gmail.com>
Made-with: Cursor
Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…ormance

- Changed key type from std::string to std::string_view to reduce unnecessary copies.
- Updated key member check in merge_values to utilize the new key type.

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
…inimize unnecessary copies.

Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
Signed-off-by: patrick.nogueira@fox.com
Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
Signed-off-by: patrick.nogueira@fox.com
Signed-off-by: patrick.nogueira@fox.com <patrick.nogueira@fox.com>
@roshkhatri
roshkhatri force-pushed the feat--JSON.MERGE-Command branch from bdbf4b4 to b1f8569 Compare March 6, 2026 21:30
@roshkhatri

Copy link
Copy Markdown
Member

There were some stray changes in the history, removed and pushed it, should be easier to review the PR now

Signed-off-by: Roshan Khatri <rvkhatri@amazon.com>
@roshkhatri
roshkhatri force-pushed the feat--JSON.MERGE-Command branch from 787e805 to c57b920 Compare March 6, 2026 22:31
Comment thread src/commands/json.merge.json Outdated
Co-authored-by: Roshan Khatri <117414976+roshkhatri@users.noreply.github.com>
Signed-off-by: Patrick Nery Nogueira <119355744+patrickn2@users.noreply.github.com>

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for getting to this much later than I thought I would. I was playing with this change with AI. I think this needs one more pass.

I can reproduce two issues:

  1. Recursive descent behaves differently from JSON.SET when the path matches both a parent and a child.

    JSON.SET k . '{"a":{"a":1}}'
    JSON.MERGE k '$..a' '5'
    JSON.GET k
    

    This returns {"a":{"a":5}}. For the same path, JSON.SET k '$..a' 5 gives {"a":5}. It looks like JSON.MERGE keeps applying child paths after the parent was already replaced.

  2. The max document size check seems to miss multi-target merges. If the same patch is merged into two matched paths, JSON.MERGE can return OK even though the final document is over json.max-document-size.

@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

We should plan to get this merged soon so we can release this command this year!

patrickn2 and others added 3 commits June 30, 2026 17:07
Signed-off-by: Patrick Nogueira <patricknn@gmail.com>
Signed-off-by: Patrick Nogueira <patricknn@gmail.com>
Signed-off-by: Patrick Nery Nogueira <119355744+patrickn2@users.noreply.github.com>
@patrickn2

Copy link
Copy Markdown
Contributor Author

Ok I fixed your issue @sarthakaggarwal97
I also did a double check against the RFC and fixed other edge cases.
please let me know if you guys need any other fix

@patrickn2

Copy link
Copy Markdown
Contributor Author

Fixing Lint errors

Signed-off-by: Patrick Nogueira <patricknn@gmail.com>
@patrickn2

Copy link
Copy Markdown
Contributor Author

Lint Errors fixed

@roshkhatri roshkhatri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, Thank you for working on this, my concerns were also inline with Sarthak's and they seem to be resolved.

Thanks @sarthakaggarwal97 for reviewing this, was waiting for it.

Thanks @patrickn2 for working on this.

Comment thread src/json/dom.cc
Comment on lines +350 to +356
bool covered_by_ancestor = false;
for (auto &other : rs) {
if (&other == &vInfo) continue;
if (path_is_ancestor(other.second, path)) {
covered_by_ancestor = true;
break;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, The time complexity would be O(N^2) for is any other path an ancestor of this path. we can mention that. Also N would be bounded by the doc size limits.

Not a blocker, just putting it out there.

@roshkhatri
roshkhatri merged commit dcaa82c into valkey-io:unstable Jul 1, 2026
19 checks passed
@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

We should have a documentation update as well for this.

@roshkhatri

Copy link
Copy Markdown
Member

@patrickn2 Can you open a PR for this to the valkey-io/valkey-doc repository?

@patrickn2

Copy link
Copy Markdown
Contributor Author

@patrickn2 Can you open a PR for this to the valkey-io/valkey-doc repository?

Oh, Sure I can, let me work on it, I didn't know that you guys had this repo

@patrickn2

Copy link
Copy Markdown
Contributor Author

@patrickn2 Can you open a PR for this to the valkey-io/valkey-doc repository?

Let me know if this is enough valkey-io/valkey-doc#456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support JSON.MERGE

4 participants