cancel
Showing results for 
Search instead for 
Did you mean: 
fannullone
Flight Engineer
Flight Engineer
  • 746 Views

create a json patch

Jump to solution

given a start json file file1.json and a final file2.json

how is possible to create a patch that applied to file1.json creates fil2.json

?

0 Kudos
1 Solution

Accepted Solutions
shura
Flight Engineer
Flight Engineer
  • 711 Views

Hello fannullone,

To create a patch file, enter the command below into the command line:

diff -u file1.json file2.json > patchfile.patch

In the example above, the diff output will be saved into a file named patchfile.patch.

Overwrite files with changes

Once the patch file is created,  you can use it to copy the changes to another file. For example, you may want to overwrite file1 with the changes from the updated file2. To do this, you could use syntax like this:

patch file1.json patchfile.patch

View solution in original post

0 Kudos
2 Replies
alexcorcoles
Flight Engineer
Flight Engineer
  • 720 Views

There might be some tools to diff JSON that could produce JSON patches. I am not aware of any. You could also probably create a JSON patch (RFC 6902) from the target JSON that completely overwrote the original JSON.

However, without more context, it's difficult to say if this would solve a particular problem. But I can see how it might make some issues worse

0 Kudos
shura
Flight Engineer
Flight Engineer
  • 712 Views

Hello fannullone,

To create a patch file, enter the command below into the command line:

diff -u file1.json file2.json > patchfile.patch

In the example above, the diff output will be saved into a file named patchfile.patch.

Overwrite files with changes

Once the patch file is created,  you can use it to copy the changes to another file. For example, you may want to overwrite file1 with the changes from the updated file2. To do this, you could use syntax like this:

patch file1.json patchfile.patch

0 Kudos
Join the discussion
You must log in to join this conversation.