Reputation: 11
I'm wondering if anyone else has run into this issue and if there's a quick work around. Seems like the terms "infinity" and "NaN" aren't treated as strings by the REST API's JSON parser so any queries or results that include those terms result in an error.
This query:
/v1/search?q=infinity&format=json
Results in this error:
<error-response xmlns="http://marklogic.com/xdmp/error">
<status-code>400</status-code>
<status>Bad Request</status>
<message-code>XDMP-JSONCHAR</message-code>
<message>
XDMP-JSONCHAR: xdmp:unquote("{"snippet-format":"snippet","total"...") -- Unexpected character 'I' in JSON at line 1 char 668
</message>
</error-response>
In my case the word "infinity" gets highlighted by the snippet function so if it sits alone as an element value the JSON parser interprets it as a number type.
We're on MarkLogic Server 8.0-6.4. I have tried this on various REST API apps and get the same results.
Upvotes: 1
Views: 117
Reputation: 8422
MarkLogic understands the symbol Infinity
(note the capital I). You can set the value of a JavaScript property to this value either using that symbol or an expression that evaluates to the value. When you look at it, you'll see a string "INF":
let foo =
{
"bar": Infinity
}
foo
which returns
{
"bar": "INF"
}
Some observations about comparing this value to other values:
foo.bar == "INF"
: falsefoo.bar === Infinity
: truefoo.bar == "Infinity"
: true (==
converts to the appropriate type)foo.bar === "Infinity"
: false (===
does not convert)Taking the next step, I serialized a query that I'd tested to be sure it would match the test document above:
xdmp.toJsonString(cts.jsonPropertyValueQuery('bar', Infinity))
I wrapped that in a {"ctsquery":{}}
, as noted in the documentation (though not real easy to find). I then tried a REST query:
http://localhost:8011/v1/search?database=Documents&structuredQuery={"ctsquery":{"jsonPropertyValueQuery":{"property":["bar"],"value":["INF"],"options":["lang=en"]}}}
That did not match. I believe that's a difference between JavaScript objects and JSON (which is a serialization of JavaScript objects).
The ECMA standard called "The JSON Data Interchange Syntax" has this to say:
"Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted"
Upvotes: 1