Making an XQuery function to call the explicit constructor with variable key 
names or number  of keys is not possible directly 
There isn't the equivalent of map:entry , field names are constant expressions 
and the number of fields is constant, unlike element {}{}

You would have to resort to string conversions, in memory node operations or 
evals ...  Or stick with json:object() /json:array() 
Or write it in Javascript 

In all cases what would the signature be?   A fundamental mismatch between 
XQuery an JSON is sequences vs arrays there are no vararg functions and any 
construct to nest or bound sequences involves a lot of syntax and temporary 
objects.

If you come up with something let us know!  





Sent from my iPad (excuse the terseness) 
David A Lee
[email protected]


> On Mar 12, 2015, at 9:51 PM, Michael Blakeley <[email protected]> wrote:
> 
> I tend to avoid declaring functions or variables in any namespace that I know 
> other code is using. But you're doing it with your eyes open, and that's 
> probably ok. Someday a server update may conflict. But if that happens, I'm 
> sure you'll catch it in testing, and fix it before it breaks production.
> 
> Right?
> 
> -- Mike  
> 
>> On 12 Mar 2015, at 17:35 , Will Thompson <[email protected]> wrote:
>> 
>> Thanks all. The ML8 constructors look very nice.
>> 
>> Mike - That's what I was looking for, thanks. I ended up writing something 
>> similar using json:array before I saw the reply, but I like your 
>> implementation better. Also, I appropriated the json: prefix because it 
>> looked nicer...for example, is there any reason why this would be bad (other 
>> than ML might decide implement it at some later date)? 
>> 
>> declare function json:new(...)
>> 
>> -W
>> 
>>> On Mar 12, 2015, at 4:38 PM, Sudhakar Reddy <[email protected]> 
>>> wrote:
>>> 
>>> You can also build using JSON node constructors available in ML 8
>>> let $json-node := object-node { "id": number-node {12345},
>>>                "a" : array-node {1,2,3} ,
>>>                "b" : fn:true(),
>>>                "c" : number-node {1234},
>>>                "d" : array-node{
>>>                        number-node {12345},
>>>                        text {"test"},
>>>                        boolean-node {fn:true()},
>>>                        array-node {'aaa','bbb','ccc'}},
>>>                        "e" : object-node { "x": "hello world",
>>>                        "y": fn:false(),
>>>                        "z" : array-node {1, 'a', fn:true()}
>>>                        },
>>>                "g": null-node {}
>>>                }  
>>>                return $json-node
>>> 
>>> Thanks
>>> Sudhakar
>>> 
>>> 
>>> 
>>>> On 3/11/15, 6:52 PM, "Erik Hennum" <[email protected]> wrote:
>>>> 
>>>> Hi, Will:
>>>> 
>>>> You can use json:object() instead of map:map() for a mutable object where
>>>> order is important.
>>>> 
>>>> I think the API is the same as that of map:map otherwise.
>>>> 
>>>> JSON nodes, like XML nodes, are immutable.
>>>> 
>>>> Erik Hennum
>>>> 
>>>> ________________________________________
>>>> From: [email protected]
>>>> [[email protected]] on behalf of Will Thompson
>>>> [[email protected]]
>>>> Sent: Tuesday, March 10, 2015 5:09 PM
>>>> To: MarkLogic Developer Discussion
>>>> Subject: [MarkLogic Dev General] Constructing JSON objects
>>>> 
>>>> Is there a nice way to construct a JSON object similar to how maps can be
>>>> constructed? Typically I would just do it this way:
>>>> 
>>>> xdmp:to-json(
>>>> map:new((
>>>> map:entry('x', 1),
>>>> map:entry('y', 2)
>>>> )))
>>>> 
>>>> Except that order is important in this specific scenario, and this ruins
>>>> ordering.
>>>> 
>>>> -Will
>>>> _______________________________________________
>>>> General mailing list
>>>> [email protected]
>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>> _______________________________________________
>>>> General mailing list
>>>> [email protected]
>>>> http://developer.marklogic.com/mailman/listinfo/general
>>> 
>>> _______________________________________________
>>> General mailing list
>>> [email protected]
>>> http://developer.marklogic.com/mailman/listinfo/general
>> 
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to