fannullone
Flight Engineer
Flight Engineer
  • 350 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
  • 315 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
  • 324 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
  • 316 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.