On this page
Json files are very popular nowadays. They are used for transferring data on the internet, for configuring applications and so on. In this way, very often people need to compare Json files to see whether they were changed or not. In the same time, it can be very useful to reject one changes and to accept other. In cause you need such functionality, GroupDocs.Comparison is the best solution for you.
All you need is to add GroupDocs.Comparison library to a project and to write just a few lines of code
First thing you need is to add GroupDocs repository to the project
Add GroupDocs repository
Second thing is to add required dependency
The latest version of Comparison API can be found here
Add GroupDocs.Comparison dependency
GroupDocs.Comparison is very powerful library that has lots of options for comparing files, analyzing changes, getting details about each change, accepting or rejecting each change and so on. Here are used just a tiny part of capabilities. More information about them you can find in the documentation
Here is the code you need to compare source and target Json files
As a result you will have two files:
.jsonfile with special labels, which shows each change in the document
.htmlfile with human-readable result of comparison
These files can be used to see and analyze changes. But it is not all we want to do, the next step is much more interesting and useful.
GroupDocs.Comparison library provides not only comparison functionality, but also possibility to get list of changes, reject or accept them and apply to the result document. It can be very useful when some changes are invalid and must be reverted while other are good and must be applied to the document.
Here is the code you need to apply or reject changes in Json file
In the code above we are getting list of changes and process each of them. We are analyzing the value of
getSourceText() method. In case it contains
useJSP (properties from Json file), the change will be accepted, all other changes will be rejected. To understand what is happening, look images below. After updating, changes are applied with saving as a new file.
The result will be saved as two files
.jsonvalid Json file without changes that were rejected but with changes that were accepted
.htmlhuman-readable result file, very similar to result of comparison process, but without rejected changes
Here are screenshots of all files:
|Source Json file||Target Json file||Result Html file||Result Html file after applying changes|
As you can see, changes
6 were rejected, while changes inside properties
useJSP were left in the document. Valid resultant Json document was also saved. You can see it below
|Resultant Json file|
There are much more options available, for example, sensitivity of comparison, generating summary page and much more. Some of them are available only with valid license. You can get a free temporary license to use the API without evaluation limitations.
Along with full-featured Java/Kotlin library we provide simple, but powerful free applications.
You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSG and other documents with free to use online GroupDocs Comparison Application.
There are much more examples of using GroupDocs.Comparison with Java/Kotlin available on our GitHub page. You are free to change and use them in order to compare photos, Excel, Word, code files, PowerPoint Presentations and much more supported file formats.
- How to compare documents in the easiest way
- How to compare files in Java or Kotlin
- How to compare images using Java or Kotlin
- How to see comparison and contrast of essays
- How to compare Text, Word or PDF in Java or Kotlin
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.