JsonUtils { public static DocumentContext fromCsv(String raw) { CsvReader reader = new CsvReader(); reader.setContainsHeader(true); try { CsvContainer csv = reader.read(new StringReader(raw)); List<Map> rows = new ArrayList(csv.getRowCount()); for (CsvRow row : csv.getRows()) { rows.add(row.getFieldMap()); } return toJsonDoc(rows); } catch (Exception e) { throw new RuntimeException(e); } } private  JsonUtils(); static DocumentContext toJsonDocStrict(String raw); static DocumentContext toJsonDoc(String raw); static String toStrictJsonString(String raw); static String toJson(Object o); static Map removeCyclicReferences(Map map); static DocumentContext toJsonDoc(Object o); static Object fromJson(String s, String className); static T fromJson(String s, Class<T> clazz); static String toPrettyJsonString(DocumentContext doc); static String escapeValue(String raw); static Object nashornObjectToJavaJSON(Object jsObj); static void removeKeysWithNullValues(Object o); static StringUtils.Pair getParentAndLeafPath(String path); static void removeValueByPath(DocumentContext doc, String path); static void setValueByPath(DocumentContext doc, String path, Object value); static void setValueByPath(DocumentContext doc, String path, Object value, boolean remove); static boolean pathExists(DocumentContext doc, String path); static DocumentContext fromYaml(String raw); static DocumentContext fromCsv(String raw); static String toCsv(List<Map<String, Object>> list); static String buildPath(String parentPath, String key); static DocumentContext emptyJsonObject(); static DocumentContext emptyJsonArray(int length);  }
@Test public void testCsv() { String raw = FileUtils.toString(getClass().getResourceAsStream("test.csv")); DocumentContext doc = JsonUtils.fromCsv(raw); Match.equals(doc, "[{ foo: 'goodbye', bar: '10', baz: 'true' }, { foo: 'cruel', bar: '20', baz: 'false' }, { foo: 'world', bar: '30', baz: 'true' }]"); }