Skip to main content
Kinetic Community

Utility JSON to XML

This handler converts a JSON string into an XML string.

Downloads

By downloading this file, you acknowledge that you agree to our Terms of Service

utility_json_to_xml_v1.zip

Detailed Description

Below are some examples of JSON input strings and the corresponding XML output
generated by this handler.
 
JSON Input
{
  "questions" : [
    {
      "text" : "Full Name",
      "type" : "Free Text"
    },
    {
      "text" : "Email Address",
      "type" : "Email"
    },
    {
      "text" : "Date of Birth",
      "type" : "Date"
    }
  ]
}
XML Output
<node type='Object'>
  <node type='Array' name='questions'>
    <node type='Object'>
      <node type='String' name='text'>Full Name</node>
      <node type='String' name='type'>Free Text</node>
    </node>
    <node type='Object'>
      <node type='String' name='text'>Email Address</node>
      <node type='String' name='type'>Email</node>
    </node>
    <node type='Object'>
      <node type='String' name='text'>Date of Birth</node>
      <node type='String' name='type'>Date</node>
    </node>
  </node>
</node>
 
JSON Input
{
  "questions" : [
    {
      "general fields": {
        "text" : "Name",
        "type" : "Free Text"
    },
      "other fields": {
        "size" : 30,
        "rows" : 2
      }
    },
    {
      "general fields": {
        "text" : "Email Address",
        "type" : "Email"
    },
      "other fields": {
        "size" : 50
      }
    },
    {
      "general fields": {
        "text" : "Date of Birth",
        "type" : "Date"
    },
      "other fields": {
        "hide date field" : false,
        "show calendar" : true
      }
    }
  ]
}
XML Output
<node type='Object'>
  <node type='Array' name='questions'>
    <node type='Object'>
      <node type='Object' name='general fields'>
        <node type='String' name='text'>Name</node>
        <node type='String' name='type'>Free Text</node>
      </node>
      <node type='Object' name='other fields'>
        <node type='Fixnum' name='size'>30</node>
        <node type='Fixnum' name='rows'>2</node>
      </node>
    </node>
    <node type='Object'>
      <node type='Object' name='general fields'>
        <node type='String' name='text'>Email Address</node>
        <node type='String' name='type'>Email</node>
      </node>
      <node type='Object' name='other fields'>
        <node type='Fixnum' name='size'>50</node>
      </node>
    </node>
    <node type='Object'>
      <node type='Object' name='general fields'>
        <node type='String' name='text'>Date of Birth</node>
        <node type='String' name='type'>Date</node>
      </node>
      <node type='Object' name='other fields'>
        <node type='FalseClass' name='hide date field'>false</node>
        <node type='TrueClass' name='show calendar'>true</node>
      </node>
    </node>
  </node>
</node>
 
Below are some examples of how to configure the loop head handler to use an XML
structure that would be returned by this handler.  The examples below are
written specifically for the XML string above.
 
This XPath will result in a loop that iterates over each object within the
array, in this case it loops over each question object.  Also note that in this
example the loop variable itself will be another XML string.
//node/node[@type="Array"]/node[@type="Object"]
 
This XPath will result in a loop that iterates over each node within a general
fields object.  For the XML above the resulting loop variables will be:  Name,
Free Text, Email Address, Email, Date of Birth, and Date.
//node/node[@type="Array"]/node[@type="Object"]/
    node[@name="general fields"]/node
 
This XPath will result in a loop that iterates over each node within an other
fields object.  For the XML above the resulting loop variables will be:  30, 2,
50, false, and true.
//node/node[@type="Array"]/node[@type="Object"]/node[@name="other fields"]/node
 

Parameters

Name Description
JSON The JSON String to be converted to XML.

Sample Configuration

Parameter Example Configuration
JSON <%=@answers['VM Name']%>

Results

Name Description
XML An XML String that was converted from the given JSON

Change Log

Version Date Description
V1 2011-04-12 Initial Version