Coder Social home page Coder Social logo

eggachecat / jycm Goto Github PK

View Code? Open in Web Editor NEW
74.0 6.0 12.0 2.35 MB

A flexible json diff framework for minimalist.

Home Page: https://jycm.readthedocs.io

License: Other

Makefile 0.69% Python 99.31%
json diff json-diff jsondiff json-diff-renderer jsondiffrender render renderer jsondiffpathch delta

jycm's People

Contributors

eggachecat avatar rohanpatankar926 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jycm's Issues

Lowercase true and false, and null values in JSON throw a NameError

Edit: This should be closed as a non-issue. See my comment below.

The JSON spec indicates that the lower case true and lower case false should be used, and null should be used for null values. (I don't mean to argue whether this is right or wrong, just that it's what the spec says and it occurs in many JSON files that I work with.)

jycm accepts uppercase False and uppercase True but not lower case. The output in the visualizer shows lower case even though the raw JSON contains uppercase.

In example 1 if an all lower case true and false, is added, the module will throw NameError: name 'false' is not defined.

A value of null in the JSON file will throw a similar error

Version info:
Window 10
Python 3.8.2

from jycm.helper import dump_html_output, open_url
from jycm.jycm import YouchamaJsonDiffer


def run_example_1():

    left = {
        "a": 1,
        "b": 2,
        "d": "12345",
        "f_upper": False,
        "f_lower": false,
        "null_test": null,
        "e": [
            {
                "x": 1,
                "y": 1
            },
            {
                "x": 2,
                "y": 2
            },
            {
                "x": 3,
                "y": 3
            },
            {
                "x": 4,
                "y": 4
            },
        ]
    }

    right = {
        "a": 1,
        "b": 3,
        "c": 4,
        "f_upper": True,
        "f_lower": true,
        "null_test": 0,
        "e": [
            {
                "x": 0,
                "y": 1
            },
            {
                "x": 2,
                "y": 2
            },
            {
                "x": 3,
                "y": 3
            },
            {
                "x": 5,
                "y": 5
            },
        ]
    }

    ycm = YouchamaJsonDiffer(left, right)
    ycm.diff()  # you have to call this
    diff_result = ycm.to_dict()

    # you can find generated html in the folder
    output_dir = "c:/temp/jycm-example-1"
    # you can directly view it by clicking the index.html file inside the folder
    url = dump_html_output(left, right, diff_result, output_dir)

    # if you want to open it from python
    open_url(url)


if __name__ == '__main__':
    run_example_1()

The code examples do not open up the graph/diff view for me

I really like the diff view aspect of your project, and I would like to get that part working.

Is there an additional piece of code or config required to open up the diff view from inside a python script?
The documented code examples do not open the diff view for me. Reference: https://github.com/eggachecat/jycm#code

So far, only executing the examples for the command line open up the graph/diff view for me, but unfortunately, going that route I run into this other bug: #3

Thoughts?

Error trying to diff very large objects

Hi! When trying to diff very large json objects, it reaches the maximum recursion depth and fails for me with this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 862, in _diff_level
    return self.compare_list(level, drill)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 693, in compare_list
    return self.compare_list_with_order(level, drill)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 552, in compare_list_with_order
    score = self._compare_list_with_order(level, drill)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 420, in _compare_list_with_order
    lcs_pair_list = self.generate_lcs_pair_list(level)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 356, in generate_lcs_pair_list
    return self._generate_lcs_pair_list(level, left_size, right_size, dp_table)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 293, in _generate_lcs_pair_list
    return self._generate_lcs_pair_list(level, left_size - 1, right_size - 1, dp_table) + [
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 293, in _generate_lcs_pair_list
    return self._generate_lcs_pair_list(level, left_size - 1, right_size - 1, dp_table) + [
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 293, in _generate_lcs_pair_list
    return self._generate_lcs_pair_list(level, left_size - 1, right_size - 1, dp_table) + [
  [Previous line repeated 970 more times]
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 284, in _generate_lcs_pair_list
    if self.diff_level(TreeLevel(
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 887, in diff_level
    cache_key = f"[{level.get_key()}]@[{drill}]"
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 82, in get_key
    return f"{make_json_path_key(self.left_path)}/{make_json_path_key(self.right_path)}"
  File "/usr/local/lib/python3.9/site-packages/jycm/helper.py", line 24, in make_json_path_key
    return "->".join([f"[{v}]" if isinstance(v, int) else v for v in path_list])
  File "/usr/local/lib/python3.9/site-packages/jycm/helper.py", line 24, in <listcomp>
    return "->".join([f"[{v}]" if isinstance(v, int) else v for v in path_list])
RecursionError: maximum recursion depth exceeded while calling a Python object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/site-packages/jycm/__main__.py", line 130, in <module>
    main()
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/jycm/__main__.py", line 126, in main
    return run(left, right, rules, output, show)
  File "/usr/local/lib/python3.9/site-packages/jycm/__main__.py", line 59, in run
    same, result = diff_two_json_with_rules(left, right, rules)
  File "/usr/local/lib/python3.9/site-packages/jycm/__main__.py", line 39, in diff_two_json_with_rules
    same = ycm.diff()
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 914, in diff
    return self.diff_level(level=root_level, drill=False) == 1
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 890, in diff_level
    score = self._diff_level(level, drill)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 869, in _diff_level
    raise e
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 865, in _diff_level
    return self.compare_dict(level, drill)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 739, in compare_dict
    _score = self.diff_level(TreeLevel(
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 890, in diff_level
    score = self._diff_level(level, drill)
  File "/usr/local/lib/python3.9/site-packages/jycm/jycm.py", line 871, in _diff_level
    raise DiffLevelException(f"Error {e} [drill={drill}] when compare [{level}]")
jycm.jycm.DiffLevelException: Error maximum recursion depth exceeded while calling a Python object [drill=False] when compare 

I guess my json blob is big enough that even this didn't make a difference:
https://stackoverflow.com/a/3323013/3806701

Any ideas?

Windows can't find jycm_viewer_assets

First of all, thanks for the amazing app!

Secondly:
I tried to create an executable of my python script. When I tried to use it, I got the following error:
image
What it says basically is Windows can't find jycm\jycm_viewer_assets
The script works perfectly, but the .exe is always showing this error and I don't know how to fix it.

Is this an error on my end or a bug? Let me know! Thanks!

include the rendering tool

will you consider including the rendering tool shown in the examples as part of the repository? I think that feature really highlights what people are looking for in a tool like this, and you might get some serious traction in the project. It looks like its HTML based, and I can already see some great uses as a plugin for apps that allow you to readily examine data structures. Will you consider including this soon?

ycm.diff() only returns True or False? How do I get the JSON?

I would expect False in both the cases below because the JSON is identical and so diff() should be false, but what I'm really interested in is getting the output showing which node values are different (or need to be added/removed).

The readme shows json output, but now how to get it.

Or it could be I'm a Python newbie and am missing something obvious.

from jycm.helper import make_ignore_order_func
from jycm.jycm import YouchamaJsonDiffer

left = '{ "one" : 1, "two" : 2 }'
right = '{ "one" : 1, "two" : 2 }'
 
ycm = YouchamaJsonDiffer(left, right)

print(ycm.diff()) # returns True?

left = '{ "one" : 1, "two" : 2 }'
right = '{ "two" : 2, "one" : 1 }'
 
ycm = YouchamaJsonDiffer(left, right)

print(ycm.diff()) # returns False?

to_dict returning {} when there is diff, but diff() has not been called.

when calling to_dict but not calling diff always returns {}.

However it should either

  • Call diff() before looping over the events if it hasn't been done before
  • erorr
  • have a kwarg arg for to_dict, which will call diff().

Currently if I know there is a diff and I just want to get get the dict, I have to do 3 lines of code.

Ideally it should be possible to just say either:

differ(left, right).diff().to_dict() or
differ(left, right)to_dict(run=True) or just differ(left, right).to_dict()

Update docs to include what nopairs is for.

both ycm.to_dict(no_pairs=True) and ycm.to_dict() are used in the doc. However the return of what the pairs are isn't explained anywhere.

I would suggest updating the readme to include either:

  • A to_dict section, going over the basic options
  • Just a note explaining what pairs are, and why you would want to use no_pairs=True

Dependencies are resolved too slow when adding jycm to a poetry project

Hi there,

I'm using jycm in a poetry project and it takes ~4mins to resolve dependencies for jycm. For example:
image

I was suspecting that it could be because there is no constraint on numpy version in requirements.txt so it took a long time to search for a suitable numpy version? Could you please let me know if there is a way to speed it up? Thanks!

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.