JSON support


[SINCE Orbeon Forms 2016.1]

Receiving JSON


When a submission returns an application/json mediatype, the submission parses the received JSON and converts it to an XML representation friendly to XPath expressions.

NOTE: This is also supported with xf:instance when using the src or resource attributes, when the content is received with an application/json mediatype.

[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:

{ "given": "Mark", "family": "Smith" }

converts to:

<json type="object">

and the values can be accessed in XPath with the paths instance()/given and instance()/family.

Numbers have a type="number" attribute:

{ "name": "Mark", "age": 21 }

converts to:

<json type="object">
    <age type="number">21</age>

Booleans similarly have a type="boolean" attribute:"

{ "selected": true }

converts to:

<json type="object">
    <selected type="boolean">true</selected>

Arrays use the _ element name and the type="array" attribute:

{ "cities": ["Amsterdam", "Paris", "London"] }

converts to:

<json type="object">
    <cities type="array">

and the string "Paris" can be accessed with instance()/cities/_[2].

JSON null adds a type="null" attribute:"

{ "p": null }

converts to:

<json type="object">
    <p type="null"/>

Here is a link to more examples as part of the test suite.

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.

results matching ""

    No results matching ""