Alex Rivera | Logout

Best way to compare two JSON files in Java

Asked 2011-06-29T20:34:41.453
49

How would you suggest this task is approached?

The challenge as i see it is in presenting diff information intelligently. Before i go reinventing the wheel, is there an accepted approach of how such a comparison should be handled?

Edit
Report

1 Answer

4

I had a similar problem and ended up writing my own library:

https://github.com/algesten/jsondiff

It does both diffing/patching.

Diffs are JSON-objects themselves and have a simple syntax for object merge/replace and array insert/replace.

Example:

original
{
   a: { b: 42 }
}

patch
{
  "~a": { c: 43 }
}

The ~ indicates an object merge.

result
{
   a: { b: 42, c: 43 }
}
answered 2011-11-05T15:34:50.917

Your Answer