Java Json Format formatJSON(String jsonData)

Here you can find the source of formatJSON(String jsonData)

Description

format JSON

License

Apache License

Declaration

public static String formatJSON(String jsonData) throws JsonProcessingException, IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;

public class Main {
    private static ObjectMapper mapper = new ObjectMapper();

    public static String formatJSON(String jsonData) throws JsonProcessingException, IOException {
        Object obj = mapper.readValue(jsonData, Object.class);
        return toJSON(obj);
    }//  w w  w  .  j  a va2 s.c  o  m

    public static String toJSON(Object o) throws JsonProcessingException {
        return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(o);
    }
}

Related

  1. formatJson(Object object)
  2. formatJson(String content)