-2

Below is a JSON response from a GET API call

[{
    "_id": "60df3ffd440138383acb62cb",
    "sequence": 2412,
    "kit_config_id": {
        "_id": "60df3ffd440138383acb62c6",
        "kitDetails": [{
                "_id": "60df3ffd440138383acb62ca"
            },
            {

                "_id": "60df3ffd440138383acb62c9"

            }

        ]

    }
}]

I want to fetch the value of this _id "60df3ffd440138383acb62c9" that is inside the kitDetails.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
chirag25
  • 65
  • 2
  • 13

1 Answers1

1

Check if this is what you are looking for

List<Map<String,Object>> data = new JsonPath(json).getList("$");
    Map<String,Object> kitConfigId = (Map<String, Object>) data.get(0).get("kit_config_id");
    List<Map<String,Object>> kitDetails = (List<Map<String, Object>>) kitConfigId.get("kitDetails");
    for (Map<String, Object> kitDetail : kitDetails) {
        System.out.println(kitDetail.get("_id").toString());
    }

//60df3ffd440138383acb62ca
//60df3ffd440138383acb62c9
Pramod
  • 787
  • 4
  • 19