JSONic - is a open-sourced Java library for convenient work with json. It allows you to convert a JSON string to program objects and vice versa. You can format the output json the way you want, for example, to make it easy for a person to read it.
Deserialize JSON:
Jsonic jsonic = new Jsonic();
// {
// "java": {
// "json": "convenient"
// }
// }
JsonObject obj = jsonic.fromJson(json).getAsObject();
// convenient
String result = obj.get("java").getAsObject().get("json").getAsPrimitive().getAsString();
Serialize JSON:
class Response
{
public int code;
public String status;
@Serialize(false)
public String secret;
}
// ...
Response response = new Response();
response.code = 0;
response.status = "success";
response.secret = "This string will not be serialized";
Jsonic jsonic = new Jonic(new JsonBuilder(BuilderOptions.PRETTY));
// {
// "code": 0,
// "status": "success"
// }
String json = jsonic.toJson(response);
The JSONic is open-sourced software licensed under the MIT license.