Complete Tree Comparison Module
Use the Complete Tree Comparison Module to compare files with tree-structured data like JSON or XML files. Tricentis Data Integrity has no limitations on file size, so you can easily compare large trees.
The Complete Tree Comparison Module is part of the Tosca Data Integrity Modules And Samples.tsu subset.
Understand what you can compare
The Module helps you to detect differences in hierarchical or nested data. You can detect and report missing nodes and differences in types. You can compare the following:
-
JSON to JSON. These comparisons verify structural alignment and check for value and type mismatches, for example string vs. number.
-
JSON to XML. These comparisons consider both formats' hierarchical structures, which are mapped to a tree. Attributes don’t exist in JSON and Tosca treats every value as a string for the comparison.
-
XML to XML. These comparisons verify structural alignment and check for value and attribute mismatches.
This table explains important differences between JSON and XML files for comparisons:
|
JSON |
XML |
---|---|---|
Types |
JSON files may contain multiple data types, such as strings, numbers, booleans, arrays, or objects. With JSON to JSON comparisons, the structure and all data types must match. If they don't, Tosca reports them as different in type. |
XML files only allow string types. |
Attributes |
It's not possible to define attributes in JSON. |
XML treats most data as text, but attributes and CDATA sections can have specific text. |
Data Structure |
Both JSON and XML organize data hierarchically. Tosca reports missing target and source nodes. |
|
Value |
If a node has the same path and type in source and target, for example “1” and 1, Tosca checks whether the node's value matches and reports the result. |
ModuleAttributes
The Complete Tree Comparison Module has the following attributes:
ModuleAttribute |
Description |
---|---|
Source |
Specify the absolute path to the source file. |
Target |
Specify the absolute path to the target file. |
General Options |
Specify the absolute path to the comparison report file. |
Example
Let's say you want to compare a JSON file to an XML file.
This is your source file, Source1.json, which is located at C:\Examples\Tree Comparison\Sources\:
{
"person": {
"name": "Alice",
"age": 30,
"contacts": [
{"contact": "alice@example.com"},
{"contact": "123-456-7890"},
"END"
]
}
}
And this is your target file, Target1.xml, which is located at C:\Examples\Tree Comparison\Targets\Target1.xml:
<person>
<name>Alice</name>
<age>30</age>
<contacts>
<contact>alice@example.com</contact>
<contact type="phone">123-456-7890</contact>
</contacts>
</person>
To compare the two, you perform the following steps:
-
Create a TestCase and drop the Complete Tree Comparison Module on it.
-
Define your Source and Target.
-
Define where you want to save your comparison report. In this case, that's C:\Examples\Tree Comparison\Reports.
Load data into Tosca
Tosca compares the files in the following way:
-
It matches the root element person.
-
It compares the child nodes name, age, and contacts.
-
It maps the contacts array in the JSON file to the contacts element in the XML file. The individual objects in the array map to the contact elements in the XML file.
-
It reports attributes like phone as missing in the JSON file.
-
It reports additional nodes like END as missing in the XML file.
If you remove the attribute END and the attribute type="phone" from the second contact element in the XML file, both files are equal in structure and value.
You can use the Report Viewer to view and report on your database.