title: WSO2 ESB proxy service Escaping JSON payload when passing to jaggery js
body: <p>I am POSTing to a ESB (4.6.0) proxy service with a JSON payload.  This is a pass through proxy service that routes to a jaggery JS app.  The jaggery app is trying to access the JSON from the payload, but it is unable to because the JSON strings are escaped.</p>
  
  <p>Here are the request headers (from web --> ESB):</p>
  
  <pre><code>POST /services/testJaggPS HTTP/1.1
  Host: pb-dvwa8:7280
  Content-Length: 29
  Cache-Control: no-cache
  Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
  Content-Type: application/json
  Accept: */*
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8
  
  {
    "PARAM": "hello world" 
  }
  </code></pre>
  
  <p>And here is the JSON response from the jaggery app:</p>
  
  <pre><code>{"RESPONSE" : {"test" : "hi", "PARAM" : null, "content" : "{\n \"PARAM\" : \"HELLO WORLD\" \n}"}}
  </code></pre>
  
  <p>Note that "content" (variable that stores JSON payload from web) is being escaped.</p>
  
  <p>I have looked into message builders/formatters, but it has not solved this issue.  Here is my current proxy service (probably don't need all of the message builders):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;proxy xmlns="http://ws.apache.org/ns/synapse"
         name="testJaggPS"
         transports="https http"
         startOnLoad="true"
         trace="disable"&gt;
     &lt;target endpoint="jaggRouter"&gt;
        &lt;inSequence&gt;
           &lt;builder&gt;
              &lt;messageBuilder contentType="application/xml"
                              class="org.apache.axis2.builder.ApplicationXMLBuilder"
                              formatterClass="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
              &lt;messageBuilder contentType="application/xop+xml"
                              class="org.apache.axis2.builder.MTOMBuilder"/&gt;
              &lt;messageBuilder contentType="multipart/related"
                              class="org.apache.axis2.builder.MIMEBuilder"/&gt;
              &lt;messageBuilder contentType="application/json"
                              class="org.apache.axis2.json.JSONBuilder"
                              formatterClass="org.apache.axis2.json.JSONMessageFormatter"/&gt;
              &lt;messageBuilder contentType="application/x-www-form-urlencoded"
                              class="org.apache.axis2.builder.XFormURLEncodedBuilder"
                              formatterClass="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/&gt;
              &lt;messageBuilder contentType="text/xml"
                              class="org.apache.axis2.builder.SOAPBuilder"
                              formatterClass="org.apache.axis2.transport.http.SOAPMessageFormatter"/&gt;
              &lt;messageBuilder contentType="application/soap+xml"
                              class="org.apache.axis2.builder.SOAPBuilder"
                              formatterClass="org.apache.axis2.transport.http.SOAPMessageFormatter"/&gt;
              &lt;messageBuilder contentType="application/json/badgerfish"
                              class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/&gt;
           &lt;/builder&gt;
           &lt;property name="messageType" value="application/json" scope="axis2"/&gt;
           &lt;property name="contentType" value="application/json" scope="axis2"/&gt;
        &lt;/inSequence&gt;
        &lt;outSequence&gt;
           &lt;property name="messageType" value="application/json" scope="axis2"/&gt;
           &lt;property name="contentType" value="application/json" scope="axis2"/&gt;
           &lt;send/&gt;
        &lt;/outSequence&gt;
     &lt;/target&gt;
  &lt;/proxy&gt;
  </code></pre>
  
  <p>And here is my jaggery code:</p>
  
  <blockquote>
  <pre><code>&lt;%
  // load core files
  response.contentType = 'application/json';
  
  var url = request.getRequestURL();
  var theContent = request.getContent();  
   // note null 'PARAM' and escaped 'content'    
  response.content = {"RESPONSE" : {
    "test" : "hi",
      "PARAM" : theContent.PARAM,
      "content" : theContent
  }};
  
  %&gt;
  </code></pre>
  </blockquote>