nxsofsys / jsondiff Goto Github PK
View Code? Open in Web Editor NEWSmall tool which making diff between json data sources in RFC 6902 format.
License: MIT License
Small tool which making diff between json data sources in RFC 6902 format.
License: MIT License
In general, this project generates JSON diffs much, much better than stefankoegl/python-json-patch, but p-j-p still has everything else apart diff generation โ the most important parts are patch applying logic and unit tests. jsondiff beats python-json-patch in unit tests (because some of them fail where they shouldn't, the algorithm of p-j-p is obviously broken somewhere), but there is one testcase where jsondiff loses to p-j-p:
>>> import jsondif
>>> src = {'foo': [1, 2, 3]}
>>> dst = {'foo': [3, 1, 2, 3]}
>>> jsondiff.make(src, dst)
[{'path': '/foo/0', 'from': '/foo/2', 'op': 'move'}, {'path': '/foo/3', 'value': 3, 'op': 'add'}]
>>> import jsonpatch
>>> str(jsonpatch.JsonPatch(None).from_diff(src, dst))
'[{"path": "/foo/0", "value": 3, "op": "add"}]'
>>>
jsondiff generates a correct diff, but two operations can be shrinked into one. This is not a bug, just a reminder about a possible improvement. There may be other undiscovered test cases like this โ if I discover some, I'll let you know.
Thanks again for a simple and effective tool. :)
jsondiff.py
doesn't compare lists properly on Python 3. Here's an example (on Python 3.4.3):
>>> import jsondiff
>>> jsondiff.make(['foo', 'bar'], [1234, 'foo'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/selurvedu/jsondiff/jsondiff.py", line 281, in make
_compare_values('', None, info, src, dst)
File "/home/selurvedu/jsondiff/jsondiff.py", line 275, in _compare_values
_compare_lists(_path_join(path, key), info, src, dst)
File "/home/selurvedu/jsondiff/jsondiff.py", line 261, in _compare_lists
_item_added(path, key, info, new)
File "/home/selurvedu/jsondiff/jsondiff.py", line 205, in _item_added
index = _take_index(info.removed, item)
File "/home/selurvedu/jsondiff/jsondiff.py", line 45, in _take_index
if a[mid][0] < x: lo = mid+1
TypeError: unorderable types: str() < int()
I've tried to figure out why it works on 2.x (I was like, "What? Why would one want to compare different types implicitly? Why doesn't that even cause an exception!?") and stumbled upon this question on SO. It explains a lot, but now I'm more confused by your code (if a[mid][0] < x: lo = mid+1
). I don't understand what it was supposed to do. Can you explain?
P. S. Even though your tool has some problems, it is still better that diff generator in python-json-patch. Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.