title: How to manipulate native Json in WSO2 ESB?
body: <p>I'm trying to manipulate data in a json-request-reply scenario for a REST-API.</p>
  
  <p>To simplify my problem, let's say I want to replace all 'b' characters with a 'd' inside the payload.</p>
  
  <p>Is there a way for me to work natively on the json-data, and not convert the data to XML first?</p>
  
  <p>I'm trying to build a custom class mediator to put in my OutSequence, but since I only have access to the MessageContext, which treats the payload as XML, I'm running into problems.</p>
  
  <p>The problem is that the json cannot be transformed to and from XML.</p>
  
  <p>It has this part inside its structure:</p>
  
  <pre><code>"Destination": {
          "name": "abc",
          "type": "ST",
          "$": "\n"
       }
  </code></pre>
  
  <p>The "$" property is valid json, but since WSO2 ESB always handle data as XML inside its MessageContext, it can't transform that property to  tags obviously, so whenever I do </p>
  
  <pre><code>MessageContext.getEnvelope().getBody()
  </code></pre>
  
  <p>inside my class mediator, the response is:</p>
  
  <pre><code>&lt;Destination&gt;
    &lt;name&gt;abc&lt;/name&gt;
    &lt;type&gt;ST&lt;/type&gt;
  &lt;/Destination&gt;
  </code></pre>
  
  <p>Missing the $ property.</p>
  
  <p>I'm using the Message builder: org.apache.synapse.commons.json.JsonStreamBuilder and formatter: org.apache.synapse.commons.json.JsonStreamFormatter</p>
  
  <p>To pass through the content in normal cases (otherwise it would fail in the XML to JSON processing step). But there must be a way for me to manipulate the data as native JSON (or as a native String?) perhaps being able to get hold of the InputStream and manipulate the data from that? But I can't find a way to get to the InputStream from the Message Context?</p>