Hello everyone,
First, I want to say that I really like the JSON improvements in BaseX 8.0. Great job.
I am however having an issue when posting JSON with markup in it. For example:
let $out := map { name: 'myView', markup: "<div name='value'>Some other stuff</div>" }
http:send-request(<http:request method="POST" />, uri, $out)
The issue is that the resulting JSON body being posted has the 'markup' property xml escaped. IE:
{ "name": "myView", "markup": "<div name='value'>Some other ..... " }
I had a similar issue with file:write but resolved that by using file:write-string.
I have tried calling json:serialize on $out manually as well as declaring the option output:method to 'json'. I even tried changing the request object by inserting a http:body. IE:
<http:request method="GET"> <http:body content-type="application/json"> {json:serialize($out)} </http> </http>
Lastly, I have tried declaring the cdata-section option: declare option output:cdata-section-elements 'http:body';
Still no go...
Is this not possible? One option would be to serialize the content using file:write and then call curl. This is a workaround I have used in the past however I was hoping I was behind that now with the latest improvements to XQuery 3.1. Maybe I need to send the http:request object as a map instead of an xml node?
Thanks again for your time on all of this. - James
Hi James,
I am however having an issue when posting JSON with markup in it. For example:
I tried to reproduce your example, but it didn't work out. It seems you were storing data in a database, right? Will the data be stored in a wrong format, or is the subsequent output (serialization) that gives wrongly escaped results? Could you possibly give me a little complete example that we can try out?
Thanks in advance, Christian
let $out := map { name: 'myView', markup: "<div name='value'>Some other stuff</div>" }
http:send-request(<http:request method="POST" />, uri, $out)
The issue is that the resulting JSON body being posted has the 'markup' property xml escaped. IE:
{ "name": "myView", "markup": "<div name='value'>Some other ..... " }
I had a similar issue with file:write but resolved that by using file:write-string.
I have tried calling json:serialize on $out manually as well as declaring the option output:method to 'json'. I even tried changing the request object by inserting a http:body. IE:
<http:request method="GET"> <http:body content-type="application/json"> {json:serialize($out)}
</http> </http>
Lastly, I have tried declaring the cdata-section option: declare option output:cdata-section-elements 'http:body';
Still no go...
Is this not possible? One option would be to serialize the content using file:write and then call curl. This is a workaround I have used in the past however I was hoping I was behind that now with the latest improvements to XQuery 3.1. Maybe I need to send the http:request object as a map instead of an xml node?
Thanks again for your time on all of this.
- James
Hello Christian,
Thanks for the response. I figured out how to get around my issue. Add the method="text" attribute to the http:body.
<http:body media-type="application/json" method="text">{json:serialize($body)}</http:body>
- James
On Tue, Feb 17, 2015 at 1:37 PM, Christian Grün christian.gruen@gmail.com wrote:
Hi James,
I am however having an issue when posting JSON with markup in it. For example:
I tried to reproduce your example, but it didn't work out. It seems you were storing data in a database, right? Will the data be stored in a wrong format, or is the subsequent output (serialization) that gives wrongly escaped results? Could you possibly give me a little complete example that we can try out?
Thanks in advance, Christian
let $out := map { name: 'myView', markup: "<div name='value'>Some other stuff</div>" }
http:send-request(<http:request method="POST" />, uri, $out)
The issue is that the resulting JSON body being posted has the 'markup' property xml escaped. IE:
{ "name": "myView", "markup": "<div name='value'>Some other ..... " }
I had a similar issue with file:write but resolved that by using file:write-string.
I have tried calling json:serialize on $out manually as well as declaring the option output:method to 'json'. I even tried changing the request
object
by inserting a http:body. IE:
<http:request method="GET"> <http:body content-type="application/json"> {json:serialize($out)}
</http> </http>
Lastly, I have tried declaring the cdata-section option: declare option output:cdata-section-elements 'http:body';
Still no go...
Is this not possible? One option would be to serialize the content using file:write and then call curl. This is a workaround I have used in the
past
however I was hoping I was behind that now with the latest improvements
to
XQuery 3.1. Maybe I need to send the http:request object as a map
instead of
an xml node?
Thanks again for your time on all of this.
- James
basex-talk@mailman.uni-konstanz.de