Hi Erik,

Yes indeed, that was the missing part.  For the record, here is the correct
example (for my case), accessing in XQuery a JS array as a sequence, and
accessing the value of the property of a JS object:

xdmp.xqueryEval(
  `declare namespace json = "http://marklogic.com/xdmp/json";;
   declare variable $obj external;
   json:array-values($obj) ! map:get(., 'name')`,
  { obj: [{ name: 'name', title: 'title' }] });

Thank you!  Regards,

-- 
Florent Georges
H2O Consulting
http://h2o.consulting/


On 17 June 2017 at 08:11, Erik Hennum wrote:

> Hi, Florent:
>
> Much the way JavaScript objects turn into json:object values in XQuery,
> JavaScript arrays turn into json:array values in XQuery.
>
> When appropriate, you can use json:array-values() to convert a json:array
> value to a sequence.
>
>
> Hoping that helps,
>
>
> Erik Hennum
>
>
> ------------------------------
> *From:* general-boun...@developer.marklogic.com [
> general-boun...@developer.marklogic.com] on behalf of Florent Georges [
> li...@fgeorges.org]
> *Sent:* Friday, June 16, 2017 2:40 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] Accessing properties of in-memory
> JS object in XQuery
>
> Hi Geert,
>
> I was mot expecting Europe to still answer at this time, but that was
> counting without you ;-)  Thank you, it works indeed as a charm.
>
> But it seems I oversimplified my example.  The problem actually comes from
> the fact that the value is an array of objecst, and just iterating over it
> like a sequence of items does not work.
>
> This modified example gives this extra complexity:
>
> xdmp.xqueryEval(
>   `declare variable $obj external;
>    $obj ! map:get(., 'name')`,
>   { obj: [{ name: 'name', title: 'title' }] });
>
> Regards,
>
> --
> Florent Georges
> H2O Consulting
> http://h2o.consulting/
>
>
> On 16 June 2017 at 23:18, Geert Josten wrote:
>
>> It is a json:object (the map:map specialization)..
>>
>> Try:
>>
>>     xdmp.xqueryEval(
>>       'declare variable $obj external; map:get($obj, "name")',
>>       { obj: {name: 'name', title: 'title' }});
>>
>>
>> Cheers,
>> Geert
>>
>>
>> On 6/16/17, 9:27 PM, "general-boun...@developer.marklogic.com on behalf
>> of
>> Florent Georges" <general-boun...@developer.marklogic.com on behalf of
>> li...@fgeorges.org> wrote:
>>
>> >Hi,
>> >
>> >I have an SJS script that calls a function from an XQuery library.  It
>> >passes a JS object to the function.  The function needs to access the
>> >value of one property of the object (in this case, a string).
>> >
>> >I can't find in the documentation how XQuery code can navigate through
>> >the properties of an in-memory JS object.  Any idea?
>> >
>> >A self-contained example (my code require() an XQuery library and
>> >calls a function instead of using code evaluation, but the issue is
>> >the same):
>> >
>> >    xdmp.eval(
>> >      `declare variable $obj as external;
>> >       $obj ! xs:string(name)`,
>> >      { name: 'name', title: 'title' });
>> >
>> >I am using ML 9.
>> >
>> >Regards,
>> >
>> >--
>> >Florent Georges
>> >H2O Consulting
>> >http://h2o.consulting/
>> >_______________________________________________
>> >General mailing list
>> >General@developer.marklogic.com
>> >Manage your subscription at:
>> >http://developer.marklogic.com/mailman/listinfo/general
>>
>> _______________________________________________
>> General mailing list
>> General@developer.marklogic.com
>> Manage your subscription at:
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>
>
>
>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>


-- 
Florent Georges
http://fgeorges.org/
http://h2o.consulting/ - New website!
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to