I am sending the below POST data to an XQuery module.
When I try to read it, I have tried everything, fn:doc, from-json, etc...., I cannot find a solution. Depending of what I try to do, I either get coercion error or data is not a string.
Can anyone help me put the Artist value to an $artist variable, etc...?
Here is the post request:
curl --anyauth --user admin:admin -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json" -X POST -g "http://localhost:8030/LATEST/resources/jsontest/" -d "{"Artist" :"bowie","Weeks" : {"gte" :"1960-01-01","lte" :"2020-12-31"},"Genres":"","Released":"" }"*
and here is my code reading the POST request:
declare function test:post(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()*
{
xdmp:log($input)
};
and the result is this:
{"Artist":"bowie", "Weeks":{"gte":"1960-01-01", "lte":"2020-12-31"}, "Genres":"", "Released":""}
which looks like a json document (to my untrained eye), but i can't figure out how to "read/assign" the value for Artist (in this case "bowie") and put it in a variable.
- I tried
fn:doc, because I thought it should be adocument-node - I tried
let $artist := $input/Artist/data(), but get a coercion error - I tried many other option (
from-json, etc..)
but I always wind up with some sort of error
how can I get access to the values in the JSON? I've been running around in circles through the MarkLogic documentation and different searches and nothing seems to work.