kwid_compare_records()

kwid_compare_records()#

Compares two JSON records deeply, allowing for unordered elements. The function checks for structural and value equivalence, optionally ignoring metadata and private fields.

Prototype

BOOL kwid_compare_records(
    hgobj  gobj,
    json_t *record,          // NOT owned
    json_t *expected,        // NOT owned
    BOOL    without_metadata,
    BOOL    without_private,
    BOOL    verbose
);

Parameters

Key

Type

Description

gobj

hgobj

Handle to the GObj instance, used for logging errors.

record

json_t *

The JSON record to compare, not owned by the function.

expected

json_t *

The expected JSON record to compare against, not owned by the function.

without_metadata

BOOL

If TRUE, metadata fields (keys starting with ‘__’) are ignored during comparison.

without_private

BOOL

If TRUE, private fields (keys starting with ‘_’) are ignored during comparison.

verbose

BOOL

If TRUE, logs detailed error messages when mismatches occur.


Return Value

Returns TRUE if the records are identical, considering the specified filtering options. Returns FALSE if differences are found.

Notes

This function is useful for validating JSON records in databases or structured data comparisons. It internally calls kwid_compare_lists() for array comparisons.

Prototype

// Not applicable in JS

Prototype

# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples