From: Eduard D. <ed...@fr...> - 2020-12-21 07:40:57
|
For our apps we use: https://github.com/bramstein/xsltjson, that gives you some options. Furthermore I guess what is in your "server" ends up in the output, you'll have to normalize your "server" first. Bye, Eduard -----Original Message----- From: Nick Sincaglia <nsi...@nu...> To: Alberto Simões via Exist-open <Exi...@li...> Subject: [Exist-open] XML to JSON Date: Mon, 21 Dec 2020 01:20:32 -0600 I have a script where I am trying to convert XML to JSON. It looks like this: xquery version "3.1"; declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; declare namespace json="http://www.json.org"; (: Switch to JSON serialization :) declare option output:method "json"; declare option output:media-type "text/javascript"; let $servers-list := collection('/db/apps/partners-packages/control- center/data')//server return <servers>{$servers-list}</servers> The output looks like this: { "server" : [{ "#text" : ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n " ], "id" : "1", "name" : "Indian Server", "status" : "active", "ip-address" : "XXX.XXX.XXX.XXX", "port" : "8080", "type" : "single-delivery-system", "description" : "Server which supports many clients in India" }, { "#text" : ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n " ], "id" : "2", "name" : "N.Va.A HUB", "status" : "active", "ip-address" : "XXX.XXX.XXX.XXX", "port" : "8080", "type" : "auto-scaling-hub", "description" : "Auto scaling hub in N.Va Region" }, { "#text" : ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n " ], "id" : "3", "name" : "N.Va.B HUB", "status" : "active", "ip-address" : "XXX.XXX.XXX.XXX", "port" : "8080", "type" : "auto-scaling-hub", "description" : "Auto scaling hub in N.Va Region" }, { "#text" : ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n " ], "id" : "4", "name" : "Video", "status" : "active", "ip- address" : "XXX.XXX.XXX.XXX", "port" : "8080", "type" : "single-delivery-system" }] } I was wondering if there was a way to get rid of all of these #text arrays that get generated: "#text" : ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n " ] This array of newline characters goes away if my XML is not formatted in a easy-to-read format. Is there a serialization setting that I can set that will make these go away? Nick -- Nick Sincaglia President/FounderNueMeta, LLCDigital Media & TechnologyPhone: +1-...@nu... http://www.nuemeta.com Skype: nsincaglia _______________________________________________Exist-open mailing lis...@li... https://lists.sourceforge.net/lists/listinfo/exist-open -- Eduard Drenth, Software Architekt ed...@fr... Doelestrjitte 8 8911 DX Ljouwert +31 58 234 30 47 +31 62 094 34 28 (privé) skype: eduarddrenth https://github.com/eduarddrenth frisian.eu gpg: https://pgp.surfnet.nl/pks/lookup?search=eduarddrenth Op freed bin ik thús/wurkje ik minder |