JSON serialization/compatibility with exist-db JSON?
Wednesday, 2 January 2019 · 2 messages
AJ
Andreas Jung2 Jan 2019 15:13 #
Hi there,
I have an issue with the migration of an XQuery script from eXist to Basex:
The link
https://gist.github.com/zopyx/467a01264d53bdaa48ad27cd553cfda8
shows the script and the expected (status quo) output for XML and JSON.
Calling the script using
/rest/foo/?run=foo.xql&method=json
generates an HTTP response with
Content-Type: application/json;charset=utf-8
but the output is a quoted XML string like:
"<item><uri>\/foo\/de\/ayapedia\/addendums\/ernaehrung_9861fc6a-ba68-11e8-a8a1-001c4210b7a0\/current-20180920-111838.bak\/xml\/index.xml<\/uri><title>Ernährung<\/title><description\/><language>de<\/language><status>current<\/status><area>ayapedia<\/area><path\/><date>2018-09<\/date><url\/><atc_code\/><guideline_id>bef53078-2d8d-42d1-af8c-b3d387dfa52e<\/guideline_id><plone_uuid>464520ec154a42839b9f5d2635caccaf<\/plone_uuid><old_authors_additional\/><authors_additional>für den Arbeitskreis Ernährung, Stoffwechsel und Bewegung der
DGHO<\/authors_additional><documenttype>ayapedia<\/documenttype><societies xmlns:json=\"http:\/\/basex.org\/modules\/json\"
json:array=\"true\">dgho<\/societies><guideline_topics
xmlns:json=\"http:\/\/basex.org\/modules\/json\"
json:array=\"true\">183<\/guideline_topics><authors xmlns:json=\"http:\/\/ basex.org\/modules\/json\" json:array=\"true\">9211<\/authors><authors xmlns:json=\"http:\/\/basex.org\/modules\/json\"
json:array=\"true\">5577<\/authors><authors
xmlns:json=\"http:\/\/basex.org\/modules\/json\"
json:array=\"true\">13728<\/authors><authors
xmlns:json=\"http:\/\/basex.org\/modules\/json\"
json:array=\"true\">373215<\/authors><\/item>"
Calling
/rest/foo/?run=foo.xql&method=json&json=format=jsonml"
finally generates JSON but not in the related format.
Isn't the JSON serialization supposed being standardized and compatible? Or how can I generate a JSON result that is compatible with the existing JSON response from eXist-dB?
Andreas
CG
Christian Grün2 Jan 2019 17:14 #
Hi Andreas,
Once again I must confess that I don’t know enough about eXist-db. What I can say is that only some JSON features were standardized, and not necessarily the ones that you find in eXist-db, BaseX and other processors (which were implemented much earlier).
I have just referenced some of our JSON features in another mail some minutes ago [1,2]. They might give you an impression what is possible with BaseX, and how it differs from eXist-db.
Quoted text · Andreas Jung · 1 line
> Or how can I generate a JSON result that is compatible with the existing JSON response from eXist-dB?
It may be best to export the eXist-db documents as JSON and reimport back (i.e., convert them to our JSON XML representation) in BaseX.
Out of interest: Is the eXist-db JSON format fully bidirectional? If yes, we could think about adding the conversion rules to the next version of BaseX.
Best,
Christian
[1] http://docs.basex.org/wiki/XQuery_3.1#JSON_Functions
[2] http://docs.basex.org/wiki/Json_Module
Quoted text · Andreas Jung · 22 lines
> /rest/foo/?run=foo.xql&method=json > > generates an HTTP response with > > Content-Type: application/json;charset=utf-8 > > but the output is a quoted XML string like: > > "<item><uri>\/foo\/de\/ayapedia\/addendums\/ernaehrung_9861fc6a-ba68-11e8-a8a1-001c4210b7a0\/current-20180920-111838.bak\/xml\/index.xml<\/uri><title>Ernährung<\/title><description\/><language>de<\/language><status>current<\/status><area>ayapedia<\/area><path\/><date>2018-09<\/date><url\/><atc_code\/><guideline_id>bef53078-2d8d-42d1-af8c-b3d387dfa52e<\/guideline_id><plone_uuid>464520ec154a42839b9f5d2635caccaf<\/plone_uuid><old_authors_additional\/><authors_additional>für den Arbeitskreis Ernährung, Stoffwechsel und Bewegung der DGHO<\/authors_additional><documenttype>ayapedia<\/documenttype><societies xmlns:json=\"http:\/\/basex.org\/modules\/json\" json:array=\"true\">dgho<\/societies><guideline_topics xmlns:json=\"http:\/\/basex.org\/modules\/json\" json:array=\"true\">183<\/guideline_topics><authors xmlns:json=\"http:\/\/basex.org\/modules\/json\" json:array=\"true\">9211<\/authors><authors xmlns:json=\"http:\/\/basex.org\/modules\/json\" json:array=\"true\">5577<\/authors><authors xmlns:json=\"http:\/\/basex.org\/modules\/json\" json:array=\"true\">13728<\/authors><authors xmlns:json=\"http:\/\/basex.org\/modules\/json\" json:array=\"true\">373215<\/authors><\/item>" > > Calling > > /rest/foo/?run=foo.xql&method=json&json=format=jsonml" > > finally generates JSON but not in the related format. > > Isn't the JSON serialization supposed being standardized and compatible? > Or how can I generate a JSON result that is compatible with the existing JSON response from eXist-dB? > > Andreas > >
Written for BaseX 9.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery