JsonComparator (json_comparator v1.0.3)
View SourceProvides functionality for comparing JSON structures with configurable comparison options.
Summary
Functions
Compares two JSON structures for equality with configurable options.
Functions
Compares two JSON structures for equality with configurable options.
This function performs a deep comparison of two JSON structures, supporting various data types including maps, lists, DateTime objects, and structs. It provides configurable behavior for list comparison and DateTime precision.
By default, this function stops and returns on the first difference found.
Use the deep_compare: true
option to collect all differences.
Parameters
json1
- First JSON structure to comparejson2
- Second JSON structure to compareopts
- Optional keyword list of comparison options::strict_list_order
- Whentrue
, lists must have identical order to be considered equal. Defaults tofalse
:truncate_datetime_microseconds
- Whentrue
, DateTime comparisons ignore microseconds. Defaults totrue
:error_message
- Custom error message template to use when differences are found. The string%{path}
will be replaced with the path where the difference was found. Defaults to "Submitted JSONs do not match: %{path}":deep_compare
- Whentrue
, collects all differences instead of stopping at the first one. Defaults tofalse
. Whentrue
, returns{:error, differences}
wheredifferences
is a list of{path, details}
tuples.
Returns
:ok
- When the structures are equal according to the comparison rules{:error, message}
- When differences are found anddeep_compare: false
, where message is a string indicating the path where the first difference was encountered{:error, differences}
- When differences are found anddeep_compare: true
, where differences is a list of tuples containing path and details about each difference