eggachecat / jycm Goto Github PK
View Code? Open in Web Editor NEWA flexible json diff framework for minimalist.
Home Page: https://jycm.readthedocs.io
License: Other
A flexible json diff framework for minimalist.
Home Page: https://jycm.readthedocs.io
License: Other
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()
Is it possible to display the original names of left and right files in the browser instead of left and right
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?
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?
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:
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!
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?
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?
when calling to_dict but not calling diff always returns {}.
However it should either
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()
Could you make optional parameters that take a filename? Instead of only being able to pass in raw json?
I'm running into an issue where it errors out because my json objects are too big to pass in as command line args.
Reference: https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x
Error message: OSError: [Errno 7] Argument list too long: '/bin/sh'
Seems like the easy fix would be to accept json filenames as input args.
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:
no_pairs=True
Hi there,
I'm using jycm in a poetry project and it takes ~4mins to resolve dependencies for jycm. For example:
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!
Is it possible to apply a diff to a JSON suture, in order to modify it.
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.