Thursday, May 5, 2016

Speaking JSON

JSON is the most popular format for browser/server communication. It is used more and more for all types of web services and as time goes it becomes more and more likely that you will encounter web services based on JSON rather than XML.

So Orbeon Forms had to support JSON, which is why we worked hard to ship Orbeon Forms 2016.1 with JSON support out of the box!

We considered two levels of JSON support:

  • First, within the forms engine.
  • Second, from Form Builder and Form Runner.

With Orbeon Forms 2016.1, JSON support is fully integrated at the XForms level, and submissions (service calls) can send and receive JSON.

Because natively XForms is XML-based, JSON goes through a transformation when it is received, following the proposed XForms 2.0 specification. This is designed so that you can access the resulting XML with path expressions in a way very similar to how you do it in JavaScript. Say you have this JSON:


In JavaScript you use the expression mother.given to find “Mary”. From XForms, you use instead mother/given. It is pretty natural in many cases. For more details, see also submissions JSON support.

Similarly, XML goes through the reverse transformation when you need to send JSON to a service. The idea is that you can roundtrip JSON from a service.

With Orbeon Forms 2016.1, Form Builder and Form Runner only have limited JSON support, but receiving JSON from a service already works: if the service response contains application/json, it is automatically processed, and you can access the received data in actions via path expressions. For more deatils, see HTTP services JSON support.

In the future, we plan to make sending JSON to services from Form Builder / Form Runner possible and user-friendly, and we also want to allow sending form data in JSON format to services. Stay tuned!

No comments:

Post a Comment