Dealing With JSON Files

The BEST way of reading nodes of a JSON file

Having trouble reading JSON file nodes or validating one of the values? You are right here. It becomes hectic sometimes even though it seems a very easy thing to solve and even there are tons of GSON, JACKSON, Jayway dependencies are sitting there.

I came across this works for me as the BEST and of course for now :) For example, once you are given like the below file and finding the batters.batter[0].id node from the below JSON file:

"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }

The best and easiest way for me is; Taking the path of the file and, copy the JSON content into for a better and visual representation.

String data = new String(Files.readAllBytes(Paths.get("src/main/java/org/api/json/mixpayload.json")));
Object nodeVal =, "batters.batter[0].id");

I dealt with the below ways also: More to come…



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store