JsonComparator (json_comparator v1.0.0)

View Source

Provides functionality for comparing JSON structures with configurable comparison options.

Summary

Functions

Compares two JSON structures for equality with configurable options.

Functions

compare(json1, json2, opts \\ [])

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.

Parameters

  • json1 - First JSON structure to compare
  • json2 - Second JSON structure to compare
  • opts - Optional keyword list of comparison options:
    • :strict_list_order - When true, lists must have identical order to be considered equal. Defaults to false
    • :truncate_datetime_microseconds - When true, DateTime comparisons ignore microseconds. Defaults to true
    • :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}"

Returns

  • :ok - When the structures are equal according to the comparison rules
  • {:error, message} - When differences are found, where message is a string indicating the path where the first difference was encountered