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