### Question:
JsonConversionUtil { static JSONObject buildHolder(JSONObject root, String[] steps, int currentStep) throws JSONException { if (currentStep > steps.length - 2) { return root; } else { Matcher matcher = ARRAY_MATCH.matcher(steps[currentStep]); if (matcher.matches()) { String fieldName = matcher.group(1); int index = Integer.parseInt(matcher.group(2)); JSONArray newArrayStep; if (root.has(fieldName)) { newArrayStep = root.getJSONArray(fieldName); } else { newArrayStep = new JSONArray(); root.put(fieldName, newArrayStep); } JSONObject newStep = new JSONObject(); newArrayStep.put(index, newStep); return buildHolder(newStep, steps, ++currentStep); } else { JSONObject newStep; if (root.has(steps[currentStep])) { newStep = root.getJSONObject(steps[currentStep]); } else { newStep = new JSONObject(); root.put(steps[currentStep], newStep); } return buildHolder(newStep, steps, ++currentStep); } } } private  JsonConversionUtil(); @SuppressWarnings("unchecked") static JSONObject fromRequest(HttpServletRequest request); static Map<String, String> fromJson(JSONObject obj); static boolean isAllLiterals(JSONArray jsonArr);  }### Answer:
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }