json and restxq
Hello again,
As we were testing the version 7.7, we ran into a problem (that actually existed in 7.6 too). We cannot produce json with restxq. We came up with a minimal file that illustrate the problem:
------- module namespace local = 'http://www.example.com/local';
declare %restxq:path("") %output:method("json") function local:test-json() { '{}' }; -------
This produce the following error :
HTTP ERROR 400 Problem accessing /. Reason: [BXJS0002] JSON serialization: Atomic values cannot be serialized.
Are we missing something ?
Best,
Jean-Philippe
Hello Jean-Philippe,
As the error statement indicates, the serializer can not serialize atomic values such as this string. Please take a look at the following part of the documentation, which describes the format to serialize to JSON: http://docs.basex.org/wiki/JSON#JSON_Functions
So for example you will need an <json /> root node. As an atomic value does not have this root node we can not serialize it.
Cheers, Dirk
Quoted text · Jean-philippe Magué · 49 lines
On 07/22/2013 04:25 PM, Jean-philippe Magué wrote: > Hello again, > > As we were testing the version 7.7, we ran into a problem (that > actually existed in 7.6 too). We cannot produce json with restxq. We > came up with a minimal file that illustrate the problem: > > > ------- > module namespace local = 'http://www.example.com/local'; > > declare %restxq:path("") > %output:method("json") > function local:test-json() { > '{}' > }; > ------- > > This produce the following error : > > HTTP ERROR 400 > Problem accessing /. Reason: > [BXJS0002] JSON serialization: Atomic values cannot be serialized. > > > Are we missing something ? > > Best, > > Jean-Philippe > > -- > Jean-Philippe Magué > Maître de Conférences en Humanités Numériques > Responsable de l'Atelier des Humanités Numériques : ahn.ens-lyon.fr > Ecole Normale Supérieure de Lyon > +33 (0)4 26 23 38 08 > > -- > > "Using computers will therefore lead us to a more profound and > systematic knowledge of human expression; in principle, it can help us > to be more humanistic than before." > Busa, 1980. > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
Written for BaseX 7.6. BaseX may have changed since: please check the current documentation.