🌐
GitHub
github.com › xlwings › jsondiff
GitHub - xlwings/jsondiff: Diff JSON and JSON-like structures in Python · GitHub
>>> d = diff({'a': 1, 'delete': 2}, {'b': 3, 'delete': 4}) >>> d {'delete': 4, 'b': 3, delete: ['a']} >>> d[jd.delete] ['a'] >>> d['delete'] 4 # Alternatively, you can use marshal=True to get back strings with a leading $ >>> diff({'a': 1, 'delete': 2}, {'b': 3, 'delete': 4}, marshal=True) {'delete': 4, 'b': 3, '$delete': ['a']} ... jdiff [-h] [-p] [-s {compact,symmetric,explicit}] [-i INDENT] [-f {json,yaml}] first second positional arguments: first second optional arguments: -h, --help show this help message and exit -p, --patch -s {compact,symmetric,explicit}, --syntax {compact,symmetric,explicit} Diff syntax controls how differences are rendered (default: compact) -i INDENT, --indent INDENT Number of spaces to indent.
Author   xlwings
🌐
GitHub
github.com › cpatrickalves › json-diff
GitHub - cpatrickalves/json-diff: A Python script that compares two JSON files and shows their differences.
In this simple project, I created a Python script that compares two JSON files and shows their differences.
Author   cpatrickalves
🌐
GitHub
github.com › monsur › jsoncompare
GitHub - monsur/jsoncompare: A simple utility to compare two JSON objects.
jsoncompare is a simple Python utility for comparing two JSON objects USAGE python jsoncompare.py <item1> <item2> Where item1 and item2 are either a file or a url containing a JSON object.
Starred by 22 users
Forked by 27 users
Languages   Python
🌐
GitHub
github.com › eggachecat › jycm
GitHub - eggachecat/jycm: A flexible json diff framework for minimalist.
python -m jycm --show --left_file /xxxx/your_left.json --right_file ~/xxxx/your_right.json ... Here's some examples showing you what you can do with JYCM. Only the results without configuration are shown below. (in case you wonder why things are not consistence here) ... from jycm.jycm import YouchamaJsonDiffer left = {} # your json right = {} # your json ycm = YouchamaJsonDiffer(left, right) diff_result = ycm.get_diff() """ ycm.get_diff() are the same as ycm.diff() ycm.to_dict*( """
Starred by 87 users
Forked by 14 users
Languages   Python 99.3% | Makefile 0.7%
🌐
GitHub
github.com › rugleb › JsonCompare
GitHub - rugleb/JsonCompare: The Python JSON Comparison package · GitHub
from jsoncomparison import Compare, NO_DIFF expected = { "project": { "name": "jsoncomparison", "version": "0.1", "license": "MIT", "language": { "name": "python", "versions": [ 3.5, 3.6 ] } }, "os": "linux" } actual = { "project": { "name": "jsoncomparison", "version": 0.1, "license": "Apache 2.0", "language": { "name": "python", "versions": [ 3.6 ] } } } diff = Compare().check(expected, actual) assert diff != NO_DIFF
Author   rugleb
🌐
GitHub
github.com › adilkhash › fastjsondiff
GitHub - adilkhash/fastjsondiff: Fast JSON Diff powered by Zig & Python
import fastjsondiff # Compare two JSON strings result = fastjsondiff.compare( '{"name": "Alice", "age": 30}', '{"name": "Bob", "age": 30, "city": "NYC"}' ) # Check if there are differences if result: print(f"Found {len(result)} differences") # Iterate over differences for diff in result: print(f"{diff.type.value}: {diff.path}") print(f" old: {diff.old_value}") print(f" new: {diff.new_value}")
Author   adilkhash
🌐
GitHub
github.com › parjun8840 › jsondiff
GitHub - parjun8840/jsondiff: Json diff using python
Jsondiff is a Python module to compare two json files. (1) Find the common key, which have different values.
Author   parjun8840
🌐
GitHub
github.com › pixelb › jsondiff
GitHub - pixelb/jsondiff: Diff JSON and JSON-like structures in Python
>>> from jsondiff import diff >>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}) {'c': 4, 'b': 3, delete: ['a']} >>> diff(['a', 'b', 'c'], ['a', 'b', 'c', 'd']) {insert: [(3, 'd')]} >>> diff(['a', 'b', 'c'], ['a', 'c']) {delete: [1]} # Typical diff looks like what you'd expect...
Author   pixelb
Find elsewhere
🌐
GitHub
github.com › jwholdsworth › jsondiff
GitHub - jwholdsworth/jsondiff: Tool to compare JSON files
Compares two JSON files, ignoring ordering and whitespace. Run ./diff.py fileA.json fileB.json -d meld
Author   jwholdsworth
🌐
GitHub
github.com › python273 › prettydiff
GitHub - python273/prettydiff: Diff parsed JSON objects and pretty-print it
prettydiff - diff parsed JSON objects and pretty-print it · $ python3 -m pip install prettydiff ·
Author   python273
🌐
GitHub
github.com › ChannelIQ › jsoncompare
GitHub - ChannelIQ/jsoncompare: A simple python library for comparing json objects for equivalency and helping developers to quickly spot differences between complex json structures.
A simple python library for comparing json objects for equivalency and helping developers to quickly spot differences between complex json structures. - GitHub - ChannelIQ/jsoncompare: A simple python library for comparing json objects for ...
Starred by 54 users
Forked by 41 users
Languages   Python
🌐
GitHub
github.com › apack1001 › json-diff-patch
GitHub - apack1001/json-diff-patch: a python clone of benjamine/jsondiffpatch
a python clone of benjamine/jsondiffpatch. Contribute to apack1001/json-diff-patch development by creating an account on GitHub.
Starred by 6 users
Forked by 2 users
Languages   Python
🌐
GitHub
github.com › topics › json-diff
json-diff · GitHub Topics · GitHub
A flexible json diff framework for minimalist. python light diff json minimal render renderer delta json-diff jsondiff minimalism json-diff-renderer jsondiffrender jsondiffpathch
🌐
GitHub
github.com › seperman › deepdiff
GitHub - seperman/deepdiff: DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together. - seperman/deepdiff
Starred by 2.5K users
Forked by 257 users
Languages   Python
🌐
GitHub
github.com › benjamine › jsondiffpatch
GitHub - benjamine/jsondiffpatch: Diff & patch JavaScript objects · GitHub
json-diff-patch (python) jsondiffpatch-react, also check docs for usage in react
Author   benjamine
Top answer
1 of 3
21

Check out this python library jsondiff , that will help you to identify the diff's

import json

import jsondiff

json1 = json.loads(
    '{"isDynamic": false, "name": "", "value": "SID:<sid>", "description": "instance","argsOrder": 1,"isMultiSelect": false}')

json2 = json.loads(
    '{ "name": "", "value": "SID:<sid>","isDynamic": false, "description": "instance","argsOrder": 1,"isMultiSelect": false}')

res = jsondiff.diff(json1, json2)
if res:
    print("Diff found")
else:
    print("Same")
2 of 3
6

UPDATED: See https://eggachecat.github.io/jycm-json-diff-viewer/ for a live demo! Now it has a JS-native implementation.

Affiliation: I am the author of this lib.

Yes! You can diff it with jycm which has a rendering tool out of the box.

It uses LCS, Edit distance and Kuhn–Munkres to diff arrays.

Here's an universal example with set in set and value changes in some set

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

left = {
    "set_in_set": [
        {
            "id": 1,
            "label": "label:1",
            "set": [
                1,
                5,
                3
            ]
        },
        {
            "id": 2,
            "label": "label:2",
            "set": [
                4,
                5,
                6
            ]
        }
    ]
}

right = {
    "set_in_set": [
        {
            "id": 2,
            "label": "label:2",
            "set": [
                6,
                5,
                4
            ]
        },
        {
            "id": 1,
            "label": "label:1111",
            "set": [
                3,
                2,
                1
            ]
        }
    ]
}

ycm = YouchamaJsonDiffer(left, right, ignore_order_func=make_ignore_order_func([
    "^set_in_set$",
    "^set_in_set->\\[\\d+\\]->set$"
]))

ycm.diff()

expected = {
    'list:add': [
        {'left': '__NON_EXIST__', 'right': 2, 'left_path': '', 'right_path': 'set_in_set->[1]->set->[1]'}
    ],
    'list:remove': [
        {'left': 5, 'right': '__NON_EXIST__', 'left_path': 'set_in_set->[0]->set->[1]', 'right_path': ''}
    ],
    'value_changes': [
        {'left': 'label:1', 'right': 'label:1111', 'left_path': 'set_in_set->[0]->label',
         'right_path': 'set_in_set->[1]->label', 'old': 'label:1', 'new': 'label:1111'}
    ]
}

assert ycm.to_dict(no_pairs=True) == expected

you can set no_pairs=False to get the all pairs. Here's a rendered example:

As for the example here, you can use it as:

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

left = {
    "data": [{"x": 1, "y": 2}, {"x": 3, "y": 4}]
}

right = {
    "data": [{"x": 3, "y": 4}, {"x": 1, "y": 2}]
}

ycm = YouchamaJsonDiffer(left, right, ignore_order_func=make_ignore_order_func([
    "^data",
]))

ycm.diff()

assert ycm.to_dict(no_pairs=True) == {}

Bonus, you the values are interrupted as coordinates on plain, you can even define a operator to determine whether two points should be matched!(Then comparing their values)

Here's the code:

from typing import Tuple

from jycm.helper import make_ignore_order_func
from jycm.jycm import YouchamaJsonDiffer
from jycm.operator import BaseOperator
import math

left = {
    "data": [
        {"x": 1, "y": 1},
        {"x": 10, "y": 10},
        {"x": 100, "y": 100}
    ]
}

right = {
    "data": [
        {"x": 150, "y": 150},
        {"x": 10, "y": 11},
        {"x": 2, "y": 3}
    ]
}


class L2DistanceOperator(BaseOperator):
    __operator_name__ = "operator:l2distance"
    __event__ = "operator:l2distance"

    def __init__(self, path_regex, distance_threshold):
        super().__init__(path_regex=path_regex)
        self.distance_threshold = distance_threshold

    def diff(self, level: 'TreeLevel', instance, drill: bool) -> Tuple[bool, float]:
        distance = math.sqrt(
            (level.left["x"] - level.right["x"]) ** 2 + (level.left["y"] - level.right["y"]) ** 2
        )
        info = {
            "distance": distance,
            "distance_threshold": self.distance_threshold,
            "pass": distance < self.distance_threshold
        }

        if not drill:
            instance.report(self.__event__, level, info)
            return False, 1 if info["pass"] else 0
        return True, 1 if info["pass"] else 0


ycm = YouchamaJsonDiffer(left, right, ignore_order_func=make_ignore_order_func([
    "^data$",
]), custom_operators=[
    L2DistanceOperator("^data->\\[.*\\]$", 10),
])

ycm.diff()

expected = {
    'just4vis:pairs': [
        {'left': 1, 'right': 2, 'left_path': 'data->[0]->x', 'right_path': 'data->[2]->x'},
        {'left': {'x': 1, 'y': 1}, 'right': {'x': 2, 'y': 3}, 'left_path': 'data->[0]',
         'right_path': 'data->[2]'},
        {'left': 1, 'right': 3, 'left_path': 'data->[0]->y', 'right_path': 'data->[2]->y'},
        {'left': {'x': 1, 'y': 1}, 'right': {'x': 2, 'y': 3}, 'left_path': 'data->[0]',
         'right_path': 'data->[2]'},
        {'left': {'x': 1, 'y': 1}, 'right': {'x': 2, 'y': 3}, 'left_path': 'data->[0]',
         'right_path': 'data->[2]'}
    ],
    'list:add': [
        {'left': '__NON_EXIST__', 'right': {'x': 150, 'y': 150}, 'left_path': '', 'right_path': 'data->[0]'}
    ],
    'list:remove': [
        {'left': {'x': 100, 'y': 100}, 'right': '__NON_EXIST__', 'left_path': 'data->[2]', 'right_path': ''}
    ],
    'operator:l2distance': [
        {'left': {'x': 1, 'y': 1}, 'right': {'x': 2, 'y': 3}, 'left_path': 'data->[0]',
         'right_path': 'data->[2]', 'distance': 2.23606797749979, 'distance_threshold': 10,
         'pass': True},
        {'left': {'x': 10, 'y': 10}, 'right': {'x': 10, 'y': 11}, 'left_path': 'data->[1]',
         'right_path': 'data->[1]', 'distance': 1.0, 'distance_threshold': 10,
         'pass': True}
    ],
    'value_changes': [
        {'left': 1, 'right': 2, 'left_path': 'data->[0]->x', 'right_path': 'data->[2]->x', 'old': 1, 'new': 2},
        {'left': 1, 'right': 3, 'left_path': 'data->[0]->y', 'right_path': 'data->[2]->y', 'old': 1, 'new': 3},
        {'left': 10, 'right': 11, 'left_path': 'data->[1]->y', 'right_path': 'data->[1]->y', 'old': 10, 'new': 11}
    ]
}
assert ycm.to_dict() == expected

As you can see jycm report addition and remove for points {'x': 150, 'y': 150} and {'x': 100, 'y': 100} for their distances are too far (more than 10) and value-change for the other two points.

P.S. RENDERER DEMO

🌐
GitHub
github.com › topics › json-comparison
json-comparison · GitHub Topics · GitHub
It can compare two JSON files, using strings, prefixes, or regex to filter required/optional fields, and apply relative or absolute precision tolerance per each numeric field or globally; prints the diff between 2 json files. It can optionally accept a config with required or optional fields. python diff regex filter cython python3 tolerance precision jsondiff comparison-tool json-compare json-comparison jsondiffviewer
🌐
PyPI
pypi.org › project › jsondiff
jsondiff · PyPI
Diff JSON and JSON-like structures in Python.
      » pip install jsondiff
    
Published   Aug 29, 2024
Version   2.2.1
🌐
GitHub
github.com › topics › jsondiff
jsondiff · GitHub Topics
It can compare two JSON files, using strings, prefixes, or regex to filter required/optional fields, and apply relative or absolute precision tolerance per each numeric field or globally; prints the diff between 2 json files. It can optionally accept a config with required or optional fields. python diff regex filter cython python3 tolerance precision jsondiff comparison-tool json-compare json-comparison jsondiffviewer