Skip to content

JSON equals is inconsistent in comparisons #44

@ryanjdew

Description

@ryanjdew

JSON equals isn't always correct. See the following example:

xquery version "1.0-ml";

import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";

let $json-string1 := '{
    "options":
    {
        "matchOptions": "basic",
        "merging": [
        {
            "propertyName": "ssn",
            "algorithmRef": "user-defined",
            "sourceRef":
            {
                "documentUri": "docA"
            }
        },
        {
            "propertyName": "name",
            "maxValues": "1",
            "doubleMetaphone":
            {
                "distanceThreshold": "50"
            },
            "synonymsSupport": "true",
            "thesaurus": "/mdm/config/thesauri/first-name-synonyms.xml",
            "length":
            {
                "weight": "8"
            }
        },
        {
            "default": "true",
            "strategy": "default-standard"
        }],
        "propertyDefs":
        {
            "properties": [
            {
                "namespace": "",
                "localname": "IdentificationID",
                "name": "ssn"
            },
            {
                "namespace": "",
                "localname": "PersonName",
                "name": "name"
            },
            {
                "namespace": "",
                "localname": "Address",
                "name": "address"
            }]
        },
        "mergeStrategies": [
        {
            "name": "default-standard",
            "algorithmRef": "standard",
            "maxValues": "1",
            "sourceWeights":
            {
                "source":
                {
                    "name": "SOURCE1",
                    "weight": "10"
                }
            }
        }],
        "algorithms":
        {
            "stdAlgorithm":{"namespaces":{}, "timestamp":{"path": null}},
            "custom": []
        }
    }
}'
let $json-string2 := $json-string1
return (
"JSONs equal: " || (try { fn:exists(test:assert-equal-json(xdmp:unquote($json-string1)/object-node(),xdmp:unquote($json-string2)/object-node())) } catch ($e) {fn:false()}),
"Strings equal: " || (try { fn:exists(test:assert-equal($json-string1,$json-string2)) } catch ($e) {fn:false()})
)

Output:

JSONs equal: false
Strings equal: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions