[basex-talk] JSON output in PHP client

2014-07-11 Thread Paul Swennenhuis
I've been playing a bit with BaseX the last couple of days - and very excited about the product while doing so - but now I am having problems outputting JSON from a PHP script. I have this XQuery: declare option output:method json; declare option output:json format=jsonml; json type=object {

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Christian Grün
Hi Paul, Which is what I expected after reading about the JSONML format. (Not too happy with that format, but that's another story). I agree; JSONML is a quasi-standard we have adopted, which is mainly useful for converting arbitrary XML to JSON. If you can decide how your XML format looks

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Paul Swennenhuis
Hi Christian, Thanks for the quick answer. Unfortunately your proposed solution (json:serialize) does not work in this case; BaseX returns a BXJS0002 error: JSON serializer: found, _ expected. The modified query reads: json:serialize( json type=array objects='_'{ for \$user in

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Christian Grün
I should have run your query before sending you an answer. The following query should work: json:serialize( json type=array objects='_'{ for $user in collection(saveresult)//user[_id=1f2cda8f-a18a-44ba-8d17-73626d472306] return _ testId{$user/test/_id}/testId

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Paul Swennenhuis
Still no luck: JSON serializer: testId is typed as string and cannot be nested I think I am going to move the JSON conversion to within PHP or Javascript, and keep the XQueries clean and readable. Paul json:serialize( json type=array objects='_'{ for $user in

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Dirk Kirsten
Hi Paul, no need to despair ;) The default JSON converter is the direct one (which would require testId/ to be declared an object), not JsonML. If you you want to use JsonML you can do so by using json:serialize( json type=array objects='_'{ for $user in

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Paul Swennenhuis
Ah, yes, that did the trick. I read about the options but had forgotten about it. Thanks. I will run some performance tests to decide for json:serialize or PHP internal conversion which might be considerably slower. Paul json:serialize( json type=array objects='_'{ for $user in

Re: [basex-talk] JSON output in PHP client

2014-07-11 Thread Christian Grün
Hi Paul, and thanks Dirk. One last note: If you plan to stick with JsonML, you can serialize arbitrary XML data, such as.. json:serialize( xml{ for $user in collection(saveresult)//user[_id=1f2cda8f-a18a-44ba-8d17-73626d472306] return result