Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

JavaScript Object Notation (JSON) support is included in the default distribution. JSON is another data exchangeable format like XML, but it is more lightweight and easily readable. It is based on a subset of Javascript language. Therefore, Javascript can understand JSON, and it can make Javascript objects by using JSON strings. JSON is based on key-value pairs and it uses colons to separate keys and values. JSON doesn't use end tags, and it uses braces (curly brackets) to enclose JSON Objects.

...

When it comes to converting XML to JSON and vice versa, there are two major conventions, one named "Badgerfish" and the other, “Mapped.” The main difference between these two conventions exists in the way they map XML namespaces into JSON.

Code Block

<xsl:root xmlns:xsl="http://foo.com"><data>my json string</data></xsl:root>

...

  • Using “Badgerfish”
Code Block

{"xsl:root":{"@xmlns":{"xsl":"http://foo.com"},"data":{"$":"my json string"}}}

...

If we use the namespace mapping as http://foo.com -> foo

Code Block

{"foo.root":{"data":"my json string"}}

...

Learn more information about JSON here.

Configuring WSO2 ESB for Supporting JSON

Open up is a lightweight data-interchange format. It can be used as an alternative to XML or SOAP. To enable the JSON support in Synapse, the following two JAR files should be deployed into the lib directory of Synapse.

Having deployed the necessary libraries, you should now register the JSON message builder and formatter with Synapse. Open up repository/conf/axis2.xml file of Synapse and add the following two entries under the messageBuilders and messageFormatters sections respectively.

Code Block

<messageBuilder contentType="application/json"
                         class="org.apache.axis2.json.JSONOMBuilder"/>

<messageFormatter contentType="application/json"
                         class="org.apache.axis2.json.JSONMessageFormatter"/>

Add the above two entries to the samples/axis2Client/client_repo/conf/axis2.xml file.

Excerpt
hiddentrue

...