Thanks Justin,
Here's an example:
declare function get-foo() as map:map*
{
map:get(xdmp:from-json('{"foo": [{"id": 1}, {"id": 2}]}'), "foo")
};
If I change the function return type to json:object it works, I thought
json:object might be a subtype of map:map but no.
In another case I want to get the sequence of strings ("a", "b") from the json
{"foo": ["a", "b"]}
(: 5.0 :)
let $foo as xs:string* := map:get(xdmp:from-json('{"foo": ["a", "b"]}'), "foo")
(: 5.1 :)
let $foo as xs:string* := json:array-values(map:get(xdmp:from-json('{"foo":
["a", "b"]}'), "foo"))
Is there a way of writing that to work in 5.0 and 5.1? And is that the best
approach to get a string sequence? It seems odd using functions from 3
namespaces.. maybe it would be better if xdmp:from-json was
unchanged/deprecated and a new json:decode added? Would prevent a lot of old
code breaking :)
Thanks,
Rob
-----Original Message-----
From: [email protected] on behalf of Justin Makeig
Sent: Sun 8/12/2012 23:50
To: MarkLogic Developer Discussion
Cc: Early Access
Subject: Re: [MarkLogic Dev General] xdmp:from-json() change in 5.1
Rob,
json:object is a specialization of the map:map type that preserves the ordering
of keys and allows for null values. As such, you should be able to use it with
APIs that expect a map. Please let me know if that's not the behavior you're
seeing.
Justin
Justin Makeig
Director, Product Management
MarkLogic Corporation
[email protected]
Phone: +1 650 655 2387
www.marklogic.com
On Aug 12, 2012, at 11:30 AM, Whitby, Rob, Springer Healthcare UK wrote:
> Hi,
>
> In 5.1 EA2 xdmp:from-json() now returns a json:object, is there still a way
> to get a map?
>
> Thanks,
> Rob
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general