Skip to content

How to create patch for merge_patch input ? #2018

@JeremieFiniel

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.

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