NameValueEncoding { public String make(){ StringBuffer result = new StringBuffer(); String[] token = jsonString.split("(?=(\"name\":\\[))|(?<=\\])"); for (String clip: token){ if (clip.startsWith(nameTag)){ result.append(clip.replaceAll("(\\[)|(\\])", "")); } else result.append(clip); } return result.toString(); } NameValueEncoding(String jsonString); String make();  }
@Test public void testMake(){ String testRawJson = "{\"name\":[{\"value\":\"Laboratory test panel\"}]," + "\"items\":" + " [{\"name\":[{\"value\":\"Laboratory result\"}]," + "\"items\":[{\"@class\":\"ELEMENT\"," + " \"archetype_node_id\":\"at0003\"," + " \"name\":{\"@class\":\"DV_TEXT\",\"value\":\"Comment\"}," + " \"value\":{\"@class\":\"DV_TEXT\",\"value\":\"this is free text\"}}," + " {\"@class\":\"ELEMENT\"," + " \"archetype_node_id\":\"at0001\"," + " \"name\":{\"@class\":\"DV_TEXT\",\"value\":\"Urea\"}," + " \"value\":{\"@class\":\"DV_QUANTITY\",\"magnitude\":3.6,\"units\":\"mmol/l\"}}]}," + " {\"name\":[{\"value\":\"Laboratory result #2\"}]," + " \"items\":[{\"@class\":\"ELEMENT\"," + " \"archetype_node_id\":\"at0001\"," + " \"name\":{\"@class\":\"DV_TEXT\",\"value\":\"Creatinine\"}," + " \"value\":{\"@class\":\"DV_QUANTITY\",\"magnitude\":97.0,\"units\":\"mmol/l\"}}]}," + " {\"name\":[{\"value\":\"Laboratory result #3\"}]," + " \"items\":[{\"@class\":\"ELEMENT\"," + " \"archetype_node_id\":\"at0001\"," + " \"name\":{\"@class\":\"DV_TEXT\",\"value\":\"Sodium\"}," + " \"value\":{\"@class\":\"DV_QUANTITY\",\"magnitude\":122.0,\"units\":\"mmol/l\"}}]}," + " {\"name\":[{\"value\":\"Laboratory result #4\"}]," + " \"items\":[{\"@class\":\"ELEMENT\",\"archetype_node_id\":\"at0001\"," + " \"name\":{\"@class\":\"DV_TEXT\",\"value\":\"Potassium\"}," + " \"value\":{\"@class\":\"DV_QUANTITY\"," + " \"magnitude\":6.1,\"units\":\"mmol/l\"}}]}]}"; String made = new NameValueEncoding(testRawJson).make(); }