public static String indentJSON(final String jsonIn) throws JSONParseException{ JsonFactory fac = new JsonFactory(); try{ JsonParser parser = fac.createJsonParser(new StringReader(jsonIn)); JsonNode node = null; try{ node = jsonObjMapper.readTree(parser); } catch(JsonParseException ex){ throw new JSONParseException(ex.getMessage()); } StringWriter out = new StringWriter(); // Create pretty printer: JsonGenerator gen = fac.createJsonGenerator(out); DefaultPrettyPrinter pp = new DefaultPrettyPrinter(); pp.indentArraysWith(new DefaultPrettyPrinter.Lf2SpacesIndenter()); gen.setPrettyPrinter(pp); // Now write: jsonObjMapper.writeTree(gen, node); gen.flush(); gen.close(); return out.toString(); } catch(IOException ex){ LOG.log(Level.SEVERE, null, ex); } return jsonIn; }