Are there any Java libraries that can diff two JSON strings and generate a tree structure that you can traverse to find out what nodes were added, what nodes were deleted, and what nodes were modified?

  • 1
    fge json-patch latest release is Nov-2014, guessing the project is abandoned.
    – cheenu
    Commented Mar 28, 2019 at 15:17

2 Answers 2


I found two Java libraries that can diff two JSON strings and tell what was added, deleted, and modified. Both libraries generate output in accordance with RFC 6902 (JSON Patch):

zjsonpatch is better because it can detect items being inserted/removed from arrays. Fge json-patch cannot handle that - if an item is inserted into the middle of an array, it will think that item and every item after that was changed, since they are all shifted over by one.

Example usage for zjsonpatch:

ObjectMapper jackson = new ObjectMapper(); 
JsonNode beforeNode = jackson.readTree(beforeString); 
JsonNode afterNode = jackson.readTree(afterString); 
JsonNode patchNode = JsonDiff.asJson(beforeNode, afterNode); 
String diff = patchNode.toString();

I did some research to finalise a diff generation library for myself. The bug pointed out by @pacoverflow seems resolved. I did not face this issue. My vote is for fge json-patch because of following reasons:

  1. Good documentation support.
  2. Supports serialisation.
  3. Most closely follows RFC 6902 standards. zjsonpatch may behave different with int and float value comparison (treating 1 and 1.0 different).
  4. Open bugs with zjsonpatch indicate possibility of broken patches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.