Hi Marco,
What about using a root element like :
<json type='array'> ... </json>
Best regards, Fabrice ETANCHAUD
-----Message d'origine----- De : basex-talk-bounces@mailman.uni-konstanz.de [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de Marco Lettere Envoyé : lundi 23 janvier 2017 09:32 À : BaseX basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] RestXQ returning JSON
Hello all,
this morning just stumbled into this issue and I'm wondering whether it could be somehow smoothed up ...
I have the following RestXQ function:
declare %rest:path("/f") %rest:GET %output:method("json") function a:f() { (:code ...:) };
1) Replacing comment with the following code correctly returns an empty object:
let $out := (<json type="object"></json>) return $out
2) Replacing comment with the following code correctly returns an expected exception (" [SERE0023] Only one item can be serialized with JSON." :
let $out := (<json type="object"></json>, <json type="object"></json>) return $out
3) Replacing comment with the following code returns a somewhat less expected Null-pointer exception :
let $out := (<json type="object"></json>, <json type="object"></json>) return array{$out}
4) In order to get the expected Json array I need to write the code like the following:
let $out := (<json type="object"></json>, <json type="object"></json>) return array{ $out ! json:parse(json:serialize(.), map{ "format" : "map"}) }
I'm not sure whether the array could be inferred from the sequence directly in a pattern like 2. But I would expect that 3) should work. Isn't it?
Thanks for any explanation.
Regards,
Marco.