I'm trying to extract a value from a nested JSONObject, say "id". I'm using org.json.simple
package and my code looks like:
JSONArray entries = (JSONArray) response.get("entries");
JSONObject entry = (JSONObject) entries.get(0);
JSONArray runs = (JSONArray) entry.get("runs");
JSONObject run = (JSONObject) runs.get(0);
String run_id = run.get("id").toString();
where response is a JSONObject.
Is it possible to refactor the code using Fluent Interface Pattern so the code is more readable? For example,
String run_id = response.get("entries")
.get(0)
.get("runs")
.get(0)
.get("id").toString();
Thanks in advance.