Check out example codes for "pretty print json in java". It will help you in understanding the concepts better.

Code Example 1

Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(uglyJSONString);
String prettyJsonString = gson.toJson(je);

Learn ReactJs, React Native from akashmittal.com