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")
Answer from Jenish on Stack Overflow
🌐
PyPI
pypi.org › project › jsondiff
jsondiff · PyPI
Diff JSON and JSON-like structures in Python. pip install jsondiff ·
      » pip install jsondiff
    
Published   Aug 29, 2024
Version   2.2.1
🌐
GitHub
github.com › xlwings › jsondiff
GitHub - xlwings/jsondiff: Diff JSON and JSON-like structures in Python · GitHub
... >>> import jsondiff as jd >>> 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']) ...
Author   xlwings
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

🌐
pytz
pythonhosted.org › opslib › icsutils › jsondiff.html
IcsUtils.JsonDiff Common Library — OpsLib Library alpha documentation
OpsLib Library alpha documentation » · class opslib.icsutils.jsondiff.Comparator(fp1=None, fp2=None, include=[], exclude=[], ignore_add=False)[source]¶ · Main workhorse for JSON Comparator · __dict__ = <dictproxy object at 0x4b368a0>¶ · __init__(fp1=None, fp2=None, include=[], exclude=[], ignore_add=False)[source]¶ ·
🌐
Readthedocs
python-json-patch.readthedocs.io › en › stable › commandline.html
Commandline Utilities — python-json-patch 1.33 documentation
# create a patch $ jsondiff a.json b.json > patch.json # show the result after applying a patch $ jsonpatch a.json patch.json {"a": [1, 2, 3], "c": 100} $ jsonpatch a.json patch.json --indent=2 { "a": [ 1, 2, 3 ], "c": 100 } # pipe result into new file $ jsonpatch a.json patch.json --indent=2 > c.json # c.json now equals b.json $ jsondiff b.json c.json []
🌐
Snyk
snyk.io › advisor › jsondiff › functions › jsondiff.diff
How to use the jsondiff.diff function in jsondiff | Snyk
}, "tool-avrdude": { "type": "uploader", "optional": true, "version": "~1.60300.0" } } } """ raw_data = parser.ManifestParserFactory.new( contents, parser.ManifestFileType.PLATFORM_JSON ).as_dict() raw_data["frameworks"] = sorted(raw_data["frameworks"]) data = ManifestSchema().load_manifest(raw_data) assert not jsondiff.diff( data, { "name": "atmelavr", "title": "Atmel AVR", "description": ( "Atmel AVR 8- and 32-bit MCUs deliver a unique combination of " "performance, power efficiency and design flexibility.
🌐
Snyk
snyk.io › advisor › jsondiff › jsondiff code examples
Top 5 jsondiff Code Examples | Snyk
}, "tool-avrdude": { "type": "uploader", "optional": true, "version": "~1.60300.0" } } } """ raw_data = parser.ManifestParserFactory.new( contents, parser.ManifestFileType.PLATFORM_JSON ).as_dict() raw_data["frameworks"] = sorted(raw_data["frameworks"]) data = ManifestSchema().load_manifest(raw_data) assert not jsondiff.diff( data, { "name": "atmelavr", "title": "Atmel AVR", "description": ( "Atmel AVR 8- and 32-bit MCUs deliver a unique combination of " "performance, power efficiency and design flexibility.
🌐
Readthedocs
python-json-patch.readthedocs.io
python-json-patch — python-json-patch 1.22 documentation
python-json-patch is a Python library for applying JSON patches (RFC 6902). Python 2.7 and 3.4+ are supported. Tests are run on both CPython and PyPy. Contents · Tutorial · Creating a Patch · Applying a Patch · The jsonpatch module · Commandline Utilities · jsondiff ·
🌐
GitHub
github.com › vspaz › jsondiff
GitHub - vspaz/jsondiff: jsondiff is a json diff utility. 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.
jsondiff is a json diff utility. 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 ...
Author   vspaz
Find elsewhere
🌐
PyPI
pypi.org › project › json-diff
json-diff · PyPI
Generates diff between two JSON files
      » pip install json-diff
    
Published   Aug 25, 2019
Version   1.5.0
🌐
Readthedocs
python-json-patch.readthedocs.io › en › latest › commandline.html
Commandline Utilities — python-json-patch 1.22 documentation
# create a patch $ jsondiff a.json b.json > patch.json # show the result after applying a patch $ jsonpatch a.json patch.json {"a": [1, 2, 3], "c": 100} $ jsonpatch a.json patch.json --indent=2 { "a": [ 1, 2, 3 ], "c": 100 } # pipe result into new file $ jsonpatch a.json patch.json --indent=2 > c.json # c.json now equals b.json $ jsondiff b.json c.json []
🌐
Packetcoders
packetcoders.io › diff-ing-the-network-jsondiff-part-2
Diff`ing the Network (jsondiff) - Part 2
November 22, 2021 - import jsondiff as jd deleted_arps_symmetric = arp_diff['interfaces'].get(jd.delete) rprint(deleted_arps_symmetric) === { 'Ethernet1/1': { 'ipv4': { 'neighbors': { '10.1.1.2': {'ip': '10.1.1.2', 'link_layer_address': '5000.0009.0000', 'physical_interface': 'Ethernet1/1', 'origin': 'dynamic', 'age': '00:00:09'} } } } } Now we have the details of our missing ARP entry as a Python dictionary, we can use it to perform further actions.
🌐
Deviloper's Blog
deviloper.in › advanced-json-diff-checker-in-python-an-in-depth-guide
Advanced JSON Diff Checker in Python: An In-Depth Guide
September 9, 2024 - In this comprehensive guide, we'll dive into the world of JSON diff checking and explore how to build an advanced JSON diff checker in Python.
🌐
Inl
mooseframework.inl.gov › python › testers › JSONDiff.html
JSONDiff | MOOSE
[Tests] design = 'RenameBlockGenerator.md' issues = '#11640 #14128 #16885 #17710' [rename] requirement = 'The system shall be able to rename or renumber mesh blocks by:' [all_ids] type = JSONDiff input = 'rename_block.i' cli_args = 'Mesh/rename/old_block="0 1 3 2" Mesh/rename/new_block="1 2 4 3" Outputs/file_base=all_ids_out' jsondiff = 'all_ids_out.json' detail = 'identifying both old and new blocks by ID,' [] [old_ids_new_names] type = JSONDiff input = 'rename_block.i' cli_args = 'Mesh/rename/old_block="0 1" Mesh/rename/new_block="new_bottom new_right" Outputs/file_base=old_ids_new_names_out
🌐
Delft Stack
delftstack.com › home › howto › python › python json diff
How to Compare Multilevel JSON Objects Using JSON Diff in Python | Delft Stack
February 2, 2024 - This article aims to demonstrate how we can compare two multilevel JSON objects and determine whether they are the same.
🌐
Snyk
snyk.io › advisor › python packages › jsondiff
jsondiff - Python Package Health Analysis | Snyk
This will install the library and cli for jsondiff as well as its runtime dependencies. ... Diff JSON and JSON-like structures in Python.
🌐
Pythonfix
pythonfix.com › pkg › j › jsondiff
jsondiff 2.2.1 - Diff JSON and JSON-like structures in Python - PythonFix.com
October 13, 2024 - A Python implementation of the JSON5 data format. ... Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable. Generate static HTML documentation from JSON schemas
🌐
PyPI
pypi.org › project › jsondiff › 1.0.0
jsondiff
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Anl
cardinal.cels.anl.gov › python › testers › JSONDiff.html
JSONDiff | Cardinal
[Tests] design = 'RenameBlockGenerator.md' issues = '#11640 #14128 #16885 #17710' [rename] requirement = 'The system shall be able to rename or renumber mesh blocks by:' [all_ids] type = JSONDiff input = 'rename_block.i' cli_args = 'Mesh/rename/old_block="0 1 3 2" Mesh/rename/new_block="1 2 4 3" Outputs/file_base=all_ids_out' jsondiff = 'all_ids_out.json' detail = 'identifying both old and new blocks by ID,' [] [old_ids_new_names] type = JSONDiff input = 'rename_block.i' cli_args = 'Mesh/rename/old_block="0 1" Mesh/rename/new_block="new_bottom new_right" Outputs/file_base=old_ids_new_names_out