title: how to show Pretty Print JSON String in a JSP page
body: <p>I want to show a JSON string in a JSP page. I am working with Spring MVC framework. Below is the code</p>
  
  <pre><code>String result = restTemplate.getForObject(url.toString(), String.class);
  
  ObjectMapper mapper = new ObjectMapper();
  Object json = mapper.readValue(result, Object.class);
  
  String indented = mapper.defaultPrettyPrintingWriter().writeValueAsString(json);
  
  System.out.println(indented);//This print statement show correct way I need
  
  model.addAttribute("response", (indented));
  </code></pre>
  
  <p>This line <code>System.out.println(indented);</code> prints out something like this-</p>
  
  <pre><code>{
    "attributes" : [ {
      "nm" : "ACCOUNT",
      "error" : "null SYS00019CancellationException in CoreImpl fetchAttributes\n java.util.concurrent.CancellationException\n\tat java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:231)\n\tat java.util.concurrent.FutureTask.",
      "status" : "ERROR"
    } ]
  }
  </code></pre>
  
  <p>which is the way I needed to be shown using a JSP page. But when I add it to model like this-</p>
  
  <pre><code>model.addAttribute("response", (indented));
  </code></pre>
  
  <p>And then shows it out in a resultform.jsp page like below-</p>
  
  <pre><code>    &lt;fieldset&gt;
          &lt;legend&gt;Response:&lt;/legend&gt;
              &lt;strong&gt;${response}&lt;/strong&gt;&lt;br /&gt;
  
      &lt;/fieldset&gt;
  </code></pre>
  
  <p>I get something like this on the browser-</p>
  
  <pre><code>{ "attributes" : [ { "nm" : "ACCOUNT", "error" : "null    
  SYS00019CancellationException in CoreImpl fetchAttributes\n 
  java.util.concurrent.CancellationException\n\tat 
  java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:231)\n\tat 
  java.util.concurrent.FutureTask.", "status" : "ERROR" } ] }
  </code></pre>
  
  <p>which I don't need. I don't know why it get wrapped like this? I needed the way it got printed out above means like this.</p>
  
  <pre><code>{
    "attributes" : [ {
      "nm" : "ACCOUNT",
      "error" : "null SYS00019CancellationException in CoreImpl fetchAttributes\n java.util.concurrent.CancellationException\n\tat java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:231)\n\tat java.util.concurrent.FutureTask.",
      "status" : "ERROR"
    } ]
  }
  </code></pre>
  
  <p>Can anyone tell me why it got happened like this? And how can I show it in a JSP page the way I needed?</p>