GroupDocs.Comparison for Python via .NET allows developers to easily compare JSON files and detect differences in deeply nested objects, arrays, data types, and structures. This is useful for validating APIs, configurations, and large datasets where accuracy is critical.
With the API, you can:
Compare two or more JSON documents\
Highlight differences in nested objects, arrays, and values\
Use visual mode (HTML report with highlights) or textual mode (JSON diff output)\
Apply or reject detected changes programmatically
Example: Compare JSON files in Python
importgroupdocs.comparisonasgcsource_path="source.json"target_path="target.json"result_path="result.json"# Initialize the comparer with the source JSON documentwithgc.Comparer(source_path)ascomparer:# Add the target JSON documentcomparer.add(target_path)# Compare and save the result filecomparer.compare(result_path)
The resulting result.json will contain the combined JSON structure with differences highlighted inline.
Visual comparison mode
Generate a single HTML report that highlights changes visually:\
Deleted items appear in red\
Inserted or modified items appear in blue
importgroupdocs.comparisonasgcfromgroupdocs.comparison.optionsimportCompareOptionssource_path="source.json"target_path="target.json"result_path="result.html"options=CompareOptions()options.generate_summary_page=True# Include summary of changeswithgc.Comparer(source_path)ascomparer:comparer.add(target_path)comparer.compare(result_path,options)
Textual comparison mode
Produce a merged JSON file with inline diff markers:\