Contents

Popular

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Expand
titleContents

Table of Contents
indent15px
stylenone

The policy allows a user to convert the request/response to be converted from XML format to JSON format.

In recent times, usage of JSON format has been increased for serializing and transmitting structured data over a network connection like data transmission between a server and a web application. Since JSON format is not widely adopted by all organizations yet, and as most of the data exchange is done through XML in earlier networks which have not deployed JSON, conversion from JSON to XML or vice-versa has become essential for data interoperability. The policy serves the need to convert data from XML format to JSON format.

Configuration

The properties that have to be configured to use the policy are described below.


Figure 1: XML to JSON Policy Configuration attributes

PropertyDescription
Skip Namespaces

Whether to skip adding namespace declarations to XML elements while conversion or not.

Remove Namespace Prefix From ElementsWhether the namespace prefix from XML elements should be removed when reading for XMLSerializer.
Indent Factor
String Indent value for JSON Object.

Example

Sample Input

Code Block
languagejs
<ns1:BookStore xmlns:ns1="http://www.books.org">
   <ns1:Book>
      <ns1:Title>Title</ns1:Title>
      <ns1:Author>Author</ns1:Author>
      <ns1:Date>Date</ns1:Date>
      <ns1:ISBN>ISBN</ns1:ISBN>
      <ns1:Publisher>Publisher</ns1:Publisher>
   </ns1:Book>
</ns1:BookStore>

Output

Various outputs depending on changes in the configuration are given below.

Code Block
titleSkip Namespaces property set to 'false' and Indent Factor property set to '4'
languagejs
{"BookStore":    {
       "@xmlns:ns1": "http://www.books.org",
       "Book":        {
           "Title": "Title",
           "Author": "Author",
           "Date": "Date",
           "ISBN": "ISBN",
           "Publisher": "Publisher"
       }
   }}
Code Block
titleSkip Namespaces property set to 'true' and Indent Factor property set to '4'
languagejs
{"BookStore": {"Book":    {
       "Title": "Title",
       "Author": "Author",
       "Date": "Date",
       "ISBN": "ISBN",
       "Publisher": "Publisher"
   }}} 
Code Block
titleSkip Namespaces set to 'true' and Remove Namespace Prefix From Elements propety set to 'false'
languagejs
{"ns1:BookStore": {"ns1:Book":    {
       "ns1:Title": "Title",
       "ns1:Author": "Author",
       "ns1:Date": "Date",
       "ns1:ISBN": "ISBN",
       "ns1:Publisher": "Publisher"
   }}} 
Adaptavist ThemeBuilder EngineAtlassian Confluence