# Json Diffing Discussion

**URL:** <https://forum.inductiveautomation.com/t/json-diffing-discussion/96800>\
**Category:** Ignition\
**Created:** [October 2, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/json-diffing-discussion/96800 "2024-10-02T14:11:40Z")\
**Posts on this page:** 1\
**Showing post:** 35

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [October 29, 2024, 8:39pm UTC](https://forum.inductiveautomation.com/t/json-diffing-discussion/96800/35 "2024-10-29T20:39:54Z")

</div>

My implementation of a dictionary & list deepSort() recursive function:

\ ***Edit:** Keys within dictionaries (and values within lists) are not 'sorted' (alphabetically & numerically ascending) but does appear to organize keys/values of two UDTs in the _same_ order. Hmmm....

```python
def deepSort(obj, ignoreKeys=[]): # Beta
	if isinstance(obj, list):
		result = []
		for value in sorted(obj):
			if hasattr(value, ' __iter__'):
				result.append(deepSort(value))
			else:
				result.append(value)
		return result
	elif isinstance(obj, dict):
		result = {}
		for key, value in sorted(obj.items()):
			if not key in ignoreKeys:
				if hasattr(value, ' __iter__'):
					result[key] = deepSort(value)
				else:
					result[key] = value
		return result
	else: return sorted(obj)

```

I wrote this to compare two tag configs (a 'model' UDT vs 'subject' UDT) that exist in two providers. The 'path' parameters were always causing a diff, so I added the ability to ignore specific keys, though decided not to utilize in favor of a less-than-elegant search & replace on a string representation of the config... Actual usage (from script console) resembled:

```python
relTagPath = "_types_/myUDT"
modelProvider = "Provider1"
subjProvider = "Provider2"
ignoreKeys = [] # ['path']

modelTagPath = "[" + modelProvider + "]" + relTagPath
modelCfg = system.tag.getConfiguration(basePath=modelTagPath, recursive=True)[0]
sortedModelCfg = deepSort(modelCfg, ignoreKeys)

subjTagPath = "[" + subjProvider + "]" + relTagPath
subjCfg = system.tag.getConfiguration(basePath=subjTagPath, recursive=True)[0]
sortedSubjCfg = deepSort(subjCfg, ignoreKeys)

replaceString = "[########]" + relTagPath
strSortedModel = str(sortedModelCfg).replace(modelTagPath, replaceString)
strSortedSubj = str(sortedSubjCfg).replace(subjTagPath, replaceString)

print strSortedModel
print strSortedSubj
print (strSortedModel == strSortedSubj)

```

Still not sure it solves @nminchin's problem...of easily detecting _what_ is different - but appears to recursively sort iterables on the few objects I've tested with.

---

_[View the full topic](https://forum.inductiveautomation.com/t/json-diffing-discussion/96800)._
