Skip to content

Conversation

@satelliteprogrammer
Copy link

The JSON merge patch document format describes the set of modifications to a resource's content, that more closely mimics the syntax of the resource being modified.

However, and in contrast to JSON Patch (RFC 6902), a JSON Merge Patch cannot express certain modifications, e.g., changing an array element at a specific index, or setting a specific object value to null. The null value in a JSON Merge Patch is used to remove the key from the object.

The diff algorithm is not part of the RFC 7396, but it was tested against all examples provided, plus additional cases on how null values are handled.

JSON Merge Patch PR: #876
PR discussing the diff: #2018

If the content is approved, please let me know if/what documentation needs to be updated.

[Describe your pull request here. Please read the text below the line and make sure you follow the checklist.]

  • The changes are described in detail, both the what and why.
  • If applicable, an existing issue is referenced.
  • The Code coverage remained at 100%. A test case for every new line of code.
  • If applicable, the documentation is updated.
  • The source code is amalgamated by running make amalgamate.

Read the Contribution Guidelines for detailed information.

The JSON merge patch document format describes the set of modifications
to a resource's content, that more closely mimics the syntax of the
resource being modified.

However, and in contrast to JSON Patch (RFC 6902), a JSON Merge Patch
cannot express certain modifications, e.g., changing an array element
at a specific index, or setting a specific object value to null.
The null value in a JSON Merge Patch is used to remove the key from the
object.

The diff algorithm is not part of the RFC 7396, but it was tested
against all examples provided, plus additional cases on how null values
are handled.
@github-actions
Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @satelliteprogrammer
Please read and follow the Contribution Guidelines.

@coveralls
Copy link

Coverage Status

coverage: 99.194% (+0.003%) from 99.191%
when pulling d32edb3 on satelliteprogrammer:develop
into 29913ca on nlohmann:develop.

@nlohmann
Copy link
Owner

I am not sure if this feature would be widely used, so I'm opening a discussion.

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Oct 25, 2025
@satelliteprogrammer
Copy link
Author

satelliteprogrammer commented Oct 25, 2025

We had a (somewhat niche) need for this at work, that's why I've contributed here.

It's essentially a combination of 2 things:

  1. we log all our data structures in JSON, this makes it easier to parse the logs and pretty-format large data structures;
  2. we have a container that only notifies listeners on data changes.

For very large data structures, reading through a log line to find the one variable that did change is a pain. Not only that, but on some interfaces only a small amount of member variables on the entire structure are actually changing.
Given that we are already serializing in JSON, on those containers that track differences, we thought why not log only those differences using one of the available JSON patch methods. So here we are.

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

Labels

L state: please discuss please discuss the issue or vote for your favorite option tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants