JSON support
[SINCE Orbeon Forms 2016.1]
Receiving JSON
Introduction
When an xf:submission
or by an xf:instance
with a src
or resource
attribute receives content with the application/json
mediatype, Orbeon Forms parses the received JSON and converts it to an XML representation friendly to XPath expressions.
[SINCE Orbeon Forms 2017.1] In addition to the application/json
mediatype, mediatypes of the form a/b+json
are recognized.
Conversion examples
The following JSON object:
converts to:
and the values can be accessed in XPath with the paths instance()/given
and instance()/family
.
Numbers have a type="number"
attribute:
converts to:
Booleans similarly have a type="boolean"
attribute:"
converts to:
Arrays use the _
element name and the type="array"
attribute:
converts to:
and the string "Paris" can be accessed with instance()/cities/_[2]
.
JSON null
adds a type="null"
attribute:"
converts to:
Seeing the converted XML
You can visualize the XML converted from JSON with Form Builder as follows:
Create a new form.
In the Advanced tab, create a new HTTP service, name it
my-service
, provide the URL to your JSON, and save.In the Advanced tab, create a new Action, name it
show-result
, run it on form load after the controls are ready, have it callmy-service
.Still while editing the new action, in the Service Response Actions tab set the value of "(control-1)" to
saxon:serialize(., 'xml')
.
[SINCE Orbeon Forms 2019.1]
The Form Builder HTTP Service dialog supports viewing JSON response translated into XML.
Sending JSON
When setting serialization="application/json"
on xf:submission
, the source XML is converted to JSON. The source XML must be compatible with the XForms XML representation of JSON shown above to be meaningful.
Last updated