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 preserve missing values in diff #28

Open
GFoley83 opened this issue Jul 4, 2022 · 2 comments
Open

How to preserve missing values in diff #28

GFoley83 opened this issue Jul 4, 2022 · 2 comments
Labels
question Further information is requested

Comments

@GFoley83
Copy link

GFoley83 commented Jul 4, 2022

I'm confused about how to preserve missing values from when diffing two objects.

Take for example these two json blocks:

{
  "Name": "John",
  "Age": 34,
  "Origin": "Scotland",  
  "Pets": [
    {
      "Type": "Cat",
      "Name": "MooMoo",
      "Age": 3.4
    },
    {
      "Type": "Squirrel",
      "Name": "Sandy",
      "Age": 7
    }
  ]
}
{
  "Origin": "Ireland"
}

When I run a patch, I would like to end up with:

{
  "Name": "John",
  "Age": 34,
  "Origin": "Ireland",   // UPDATED HERE  
  "Pets": [
    {
      "Type": "Cat",
      "Name": "MooMoo",
      "Age": 3.4
    },
    {
      "Type": "Squirrel",
      "Name": "Sandy",
      "Age": 7
    }
  ]
}

Basically all the missing values are preserved and only the values that conflict are updated, but I can seem to achieve this.

@weichch
Copy link
Owner

weichch commented Jul 5, 2022

I think your example is merge patch (e.g. JSON Merge Patch) which is currently not supported. The patch document generated through diffing is equivalent to JSON Patch, which contains all operations required to fully transform JSON A to B. If you use the Live Demo provided by jsondiffpatch, you can visualize the document/operations.

I say currently not supported because I did plan to add some support for it at some stage.

@weichch weichch added the question Further information is requested label Jul 5, 2022
@jannikbuschke
Copy link

It would be awesome to have this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants