添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With the two attached jsons (renamed to .txt to appease github…) trying to run jsondiff.diff on them returns a list.

In my applications I already previously loaded the jsons since I'm doing some processing on them before handling them over to jsondiff, and we need to use OrderedDict for that.

transcriptions:

In [1]: import json
In [2]: import jsondiff
In [3]: import collections
In [4]: with open('1.json') as f:
   ...:     a = json.load(f, object_pairs_hook=collections.OrderedDict)
In [5]: with open('2.json') as f:
   ...:     b = json.load(f, object_pairs_hook=collections.OrderedDict)
In [6]: type(jsondiff.diff(a, b))
Out[6]: list
In [7]: jsondiff.diff(a, b)
Out[7]: 
[OrderedDict([('id', '/build/node-module-deps-6.1.0/2nd/example/files/bar.js'),
              ('source',
               'module.exports = function (n) {\n    return n * 100;\n};\n'),
              ('deps', OrderedDict()),
              ('file',
               '/build/node-module-deps-6.1.0/2nd/example/files/bar.js')]),
 OrderedDict([('id', '/build/node-module-deps-6.1.0/2nd/example/files/foo.js'),
              ('source',
               "var bar = require('./bar');\n\nmodule.exports = function (n) {\n    return n * 111 + bar(n);\n};\n"),
              ('deps',
               OrderedDict([('./bar',
                             '/build/node-module-deps-6.1.0/2nd/example/files/bar.js')])),
              ('file',
               '/build/node-module-deps-6.1.0/2nd/example/files/foo.js')]),
 OrderedDict([('file',
               '/build/node-module-deps-6.1.0/2nd/example/files/main.js'),
              ('id',
               '/build/node-module-deps-6.1.0/2nd/example/files/main.js'),
              ('source',
               "var foo = require('./foo');\nconsole.log('main: ' + foo(5));\n"),
              ('deps',
               OrderedDict([('./foo',
                             '/build/node-module-deps-6.1.0/2nd/example/files/foo.js')])),
              ('entry', True)])]
In [8]: 

Is this expected? I always saw dicts being returned by jsondiff, and also I can't spot anything in jsondiff's code that obviously returns a list out of itself.

1.txt
2.txt