Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create patch for merge_patch input ? #2018

Closed
JeremieFiniel opened this issue Mar 30, 2020 · 5 comments
Closed

How to create patch for merge_patch input ? #2018

JeremieFiniel opened this issue Mar 30, 2020 · 5 comments
Labels
kind: question state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@JeremieFiniel
Copy link

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.

@nickaein
Copy link
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).

@nlohmann
Copy link
Owner

@nickaein is right.

@dota17
Copy link
Contributor

dota17 commented Apr 8, 2020

Is there a plan to support this case?

@nlohmann
Copy link
Owner

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

@stale
Copy link

stale bot commented May 13, 2020

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.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 13, 2020
@stale stale bot closed this as completed May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

4 participants