Skip to content

How to create patch for merge_patch input ? #2018

Closed

Description

@JeremieFiniel

Hello,

I need to generate a patch like the one from merge_patch example :

// the patch
json patch = R"({
            "title": "Hello!",
            "phoneNumber": "+01-123-456-7890",
            "author": {
                "familyName": null
            },  
            "tags": [
                "example"
            ]   
        })"_json;

Is there an existing function to generate this ?
I tried diff function but it create a list of actions to apply, so not what I need.

I search somthing working like this:

// the source document
json source = R"(
    {
        "baz": "qux",
        "foo": "bar"
    }
)"_json;

// the target document
json target = R"(
    {
        "baz": "boo",
        "hello": [
            "world"
        ]
    }
)"_json;

// create the patch
json patch = json::diff(source, target);

Where patch will be

{
    "baz": "boo",
    "foo": null,
    "hello": [
        "world"
    ]   
}

Thank you for your help.

Activity

  1. nickaein commented on Mar 31, 2020

    @nickaein
    Contributor

    I don't believe this is currently supported out of the box. The library supports applying JSON Merge Patches through merge_patch‍() function, but there is no counterpart "merge_diff" function to generate one. There are some considerations before implementing a general-purpose one (e.g. how to handle null values in source).

  2. nlohmann commented on Mar 31, 2020

    @nlohmann
    Owner

    @nickaein is right.

  3. dota17 commented on Apr 8, 2020

    @dota17
    Contributor

    Is there a plan to support this case?

  4. nlohmann commented on Apr 11, 2020

    @nlohmann
    Owner

    There is no real specification for this. Merge requests are welcome!

  5. stale commented on May 13, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  6. added
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: questionstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions