Git Product home page Git Product logo

jsondiff's People

Contributors

nxsofsys avatar selurvedu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jsondiff's Issues

Diff generator optimization

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. :)

TypeError: unorderable types (Python 3)

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.