1

Is there any way to get the pretty printing feature in json simple java library.Any example would be good.

Ramesh
  • 2,295
  • 5
  • 35
  • 64
  • [try this](http://stackoverflow.com/questions/352098/how-to-pretty-print-json-script) – kev Jan 03 '12 at 10:01

2 Answers2

0

you just want for developer's perspective then install addons/extensions for your browsers

or if you really want to beautify your code then try

http://jsbeautifier.org/

xkeshav
  • 53,360
  • 44
  • 177
  • 245
0

For this purpose I am using jackson-mapper-lgpl library. There is DefaultPrettyPrinter that can help you.

Here is my Serializer:

public class JSONSerializer
{
    private ObjectMapper mapper;

public JSONSerializer() {
    this.mapper = new ObjectMapper();
}

public String serialize(Object ob) throws IOException
{
    if (ob == null) {
        throw new NullPointerException("Cannot serialize null value");
    }
    return mapper.defaultPrettyPrintingWriter().writeValueAsString(ob);
}
}
Oleksandr_DJ
  • 1,454
  • 2
  • 14
  • 26