zgrossbart / jdd

A semantic JSON compare tool
http://www.jsondiff.com
Apache License 2.0
1.05k stars 183 forks source link

JSONDiff will output invalid JSON if the original JSON has escape characters #14

Closed zgrossbart closed 6 years ago

zgrossbart commented 6 years ago

Give JSONDiff the following documents:

a.json:

1. {
2.   "comment": "a\nb",
3.   "xcheck": true
4. }

b.json:

1. {
2.   "comment": "a\nb",
3.   "xcheck": false
4. }

This should result in a diff on line three because the two values of the xcheck property don't match. It should also result in the entire value of comment property on a single line.

Instead JSONDiff will unescape the new line character with a resulting output that looks like this:

1. {
2.     "comment": "a
3. b",
4.     "xcheck": false
5. }

JSONDiff will also report the difference is still on line three which is now incorrect. This is also invalid JSON since JSON strings don't allow unescaped new line characters which is why this character was escaped in the first place.

JSONDiff should show output that looks like this:

1. {
2.     "comment": "a\nb",
3.     "xcheck": false
4. }

It should also still report the diff at line three.

This should work the same way for all of the well known escape characters in the JSON specification. It should also handle escape characters in JSON property names as well as values.

jkubos commented 6 years ago

Fix works for me. I did test on both sample data and also original (much more complex) data.

Thank you!

zgrossbart commented 6 years ago

It looks like this all works. I'm going to run through the unit tests a few more times and then deploy. I'm marking this bug closed.