JsonLoader { public DataFrame load(String json) { DocumentContext context = JsonPath.parse(json, buildJSONPathConfiguration()); return load(context); } JsonLoader(); JsonLoader pathExpression(String pathExpression); JsonLoader nullsForMissingLeafs(); DataFrame load(String json); DataFrame load(Reader reader);  }
@Test @DisplayName("$.* : root is object, properties are rows") public void testObjectProperties() { String json = "{\"a\": {\"x\":1, \"y\":2}, \"b\":{\"x\":3, \"y\":4}}"; DataFrame df = Json.loader().load(json); new DataFrameAsserts(df, "x", "y") .expectHeight(2) .expectRow(0, 1, 2) .expectRow(1, 3, 4); }
@Test @DisplayName("$.* : root is list, objects are rows") public void testListOfObjects() { String json = "[{\"a\":1, \"b\":\"B\"},{\"a\":2, \"b\":\"C\"},{\"a\":3, \"b\":\"D\"}]"; DataFrame df = Json.loader().load(json); new DataFrameAsserts(df, "a", "b") .expectHeight(3) .expectRow(0, 1, "B") .expectRow(1, 2, "C") .expectRow(2, 3, "D"); }
@Test @DisplayName("$.* : root is list, objects are rows, different property names") public void testListOfObjects_Sparse() { String json = "[{\"a\":1, \"b\":\"B\"},{\"b\":\"C\"},{\"a\":3, \"c\":\"D\"}]"; DataFrame df = Json.loader().load(json); new DataFrameAsserts(df, "a", "b", "c") .expectHeight(3) .expectRow(0, 1, "B", null) .expectRow(1, null, "C", null) .expectRow(2, 3, null, "D"); }
@Test @DisplayName("$.* : root is list, objects are rows, nested maps") public void testListOfNestedObjects() { String json = "[{\"a\":1, \"b\":{\"x\":1, \"y\":2}},{\"a\":2, \"b\":{\"x\":3, \"y\":4}}]"; DataFrame df = Json.loader().load(json); Map<String, Object> expectedMap1 = new HashMap<>(); expectedMap1.put("x", 1); expectedMap1.put("y", 2); Map<String, Object> expectedMap2 = new HashMap<>(); expectedMap2.put("x", 3); expectedMap2.put("y", 4); new DataFrameAsserts(df, "a", "b") .expectHeight(2) .expectRow(0, 1, expectedMap1) .expectRow(1, 2, expectedMap2); }