Hi all,

I have a bit of difficulty in understanding the rationale behind the XML to Json (and vice-versa) conversions.

I must admit I'm a bit confused on when to use which format and how those map to serialization/parsing rules.

In particular I'm wondering whether it's really necessary to use both the formalisms (and functions) in the following example.

My feelings are that using only the standard (?) XQuery 3.1 representation would be much clearer and would enable a cleaner service chaining mechanism.

Has anyone 2 minutes left to explain to me the model behind this sort of things?

I really appreciate your support!

Regards,

Marco.


module namespace jt = "urn:json:test";

declare
  %rest:path("jsonsrv")
  %output:method("text")
  %output:media-type("application/json")
function jt:service()
{
  xml-to-json(
    <map xmlns="http://www.w3.org/2005/xpath-functions">
      <string key="a">12345678</string>
    </map>)
};

declare
  %rest:path("testreq")
  %output:method("text")
  %output:media-type("application/json")
function jt:test()
{
  let $response := http:send-request(
    <http:request href="http://localhost:9984/jsonsrv" method="POST">
      <http:body media-type="application/x-www-form-urlencoded" method="text"/>
    </http:request>)
  return json:serialize($response[2])
};