title: Convert JSON String to Pretty Print JSON output using Jackson
body: <p>This is the JSON string I have:</p>
  
  <pre><code>{"attributes":[{"nm":"ACCOUNT","lv":[{"v":{"Id":null,"State":null},"vt":"java.util.Map","cn":1}],"vt":"java.util.Map","status":"SUCCESS","lmd":13585},{"nm":"PROFILE","lv":[{"v":{"Party":null,"Ads":null},"vt":"java.util.Map","cn":2}],"vt":"java.util.Map","status":"SUCCESS","lmd":41962}]}
  </code></pre>
  
  <p>I need to convert the above JSON <code>String</code> into Pretty Print JSON Output (using Jackson), like below:</p>
  
  <pre><code>{
      "attributes": [
          {
              "nm": "ACCOUNT",
              "lv": [
                  {
                      "v": {
                          "Id": null,
                          "State": null
                      },
                      "vt": "java.util.Map",
                      "cn": 1
                  }
              ],
              "vt": "java.util.Map",
              "status": "SUCCESS",
              "lmd": 13585
          },
          {
              "nm": "PROFILE
              "lv": [
                  {
                      "v": {
                          "Party": null,
                          "Ads": null
                      },
                      "vt": "java.util.Map",
                      "cn": 2
                  }
              ],
              "vt": "java.util.Map",
              "status": "SUCCESS",
              "lmd": 41962
          }
      ]
  }
  </code></pre>
  
  <p>Can anyone provide me an example based on my example above? How to achieve this scenario? I know there are lot of examples, but I am not able to understand those properly. Any help will be appreciated with a simple example.</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>Below is the code I am using:</p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  System.out.println(mapper.defaultPrettyPrintingWriter().writeValueAsString(jsonString));
  </code></pre>
  
  <p>But this doesn't works with the way I needed the output as mentioned above.</p>
  
  <p>Here's is the POJO I am using for the above JSON:</p>
  
  <pre><code>public class UrlInfo implements Serializable {
  
      private List&lt;Attributes&gt; attribute;
  
  }
  
  class Attributes {
  
      private String nm;
      private List&lt;ValueList&gt; lv;
      private String vt;
      private String status;
      private String lmd;
  
  }
  
  
  class ValueList {
      private String vt;
      private String cn;
      private List&lt;String&gt; v;
  }
  </code></pre>
  
  <p>Can anyone tell me whether I got the right POJO for the JSON or not?</p>
  
  <p><strong>Updated:</strong></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>Below line prints out something like this:</p>
  
  <pre><code>System.out.println(indented);
  
  
  {
    "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. 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:</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 needed the way it got printed out above. Can anyone tell me why it happened this way?</p>