Basex json module and namespaces

Wednesday, 24 July 2013 · 2 messages
AV
Arto Viitanen24 Jul 2013 08:05 #
Is there any way to make json module (mainly json:serialize) handle namespaces? I tried following:
let $str := '{"name":"Mike Mac","address":{"postnumber":20221,"city":"NYC","street":"23 west A 22"},"email":"mm at gmail.com"}'
let $json := json:parse($str)
return json:serialize($json)
and I get the string, with linefeed etc. But I would like to add the $json element inside another element, which have default namespace.
let $str := '{"name":"Mike Mac","address":{"postnumber":20221,"city":"NYC","street":"23 west A 22"},"email":"mm at gmail.com"}'
let $json := json:parse($str)
let $wrapper := copy $x := <wrapper xmlns="namespace-uri"/>
    modify (insert node $json into $x)
   return $x
let $json2 := $wrapper/*[1]
return json:serialize($json2)
(That is, insert the $json inside the <wrapper> -element, get it out and serialize it.) Instead of the same result as in the first case, I get 'BXJS0001 JSON serialization: Element <json> has invalid attribute "xmlns". ' But since it is default namespace, there is no easy way to drop it. My question is: is there any way to let json:serialize handle or ignore namespaces; at least default namespaces?
-- Arto Viitanen Microteam Oy Tampere, Finland
CG
Christian Grün24 Jul 2013 16:02 #
Hei Arto, your proposal sounds reasonable. I have fixed our json serializer; namespace declarations will now be ignored. Hope this helps, Christian ___________________________ 2013/7/24 Arto Viitanen <arto.viitanen at microteam.fi>:
Quoted text · Arto Viitanen · 75 lines
> Is there any way to make json module (mainly json:serialize) handle > namespaces? I tried following: > > > > let $str := '{"name":"Mike > Mac","address":{"postnumber":20221,"city":"NYC","street":"23 west A > 22"},"email":"mm at gmail.com"}' > > let $json := json:parse($str) > > return json:serialize($json) > > > > and I get the string, with linefeed etc. > > > > But I would like to add the $json element inside another element, which > have default namespace. > > > > let $str := '{"name":"Mike > Mac","address":{"postnumber":20221,"city":"NYC","street":"23 west A > 22"},"email":"mm at gmail.com"}' > > let $json := json:parse($str) > > let $wrapper := copy $x := <wrapper xmlns="namespace-uri"/> > > modify (insert node $json into $x) > > return $x > > let $json2 := $wrapper/*[1] > > return json:serialize($json2) > > > > (That is, insert the $json inside the <wrapper> -element, get it out and > serialize it.) > > > > Instead of the same result as in the first case, I get ‘BXJS0001 JSON > serialization: Element <json> has invalid attribute “xmlns”. ‘ > > > > But since it is default namespace, there is no easy way to drop it. > > > > My question is: is there any way to let json:serialize handle or ignore > namespaces; at least default namespaces? > > > > -- > > Arto Viitanen > > Microteam Oy > > Tampere, Finland > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >

⚡Generated with XQuery