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 
collection("saveresult")//user[_id="1f2cda8f-a18a-44ba-8d17-73626d472306"]
        return
        <testResult>
          <testId>{\$user/test/_id}</testId>
          <grade>{\$user/user_info/user_grade}</grade>
          </testResult>
        }
    </json>
)

Paul

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 like, I would recommend the standard conversion format:

declare option output:method "json";

  <json type="array" objects='_'>{
for $user in collection("saveresult")//user[_id="1f2cda8f-a18a-44ba-8d17-73626d472306"]
    return
      <testResults>
<testId>{$user/test/_id}</testId>
<grade>{$user/user_info/user_grade}</grade>
        </testResults>
  }</json>

>
 Running exactly the same XQuery form within a PHP script however yields
> this:

The query results are currently sent to all clients in their standard format (i.e., ignoring all serialization parameters). That's why you'll need to convert your JSON within XQuery:

  json:serialize(
    <json type="array" objects='_'>{
      ...
    }</json>
  )

If I remember what was the reason for that design decision, I'll give you an update soon..

Hope this helps,
Christian


Reply via email to