Skip to content

Commit

Permalink
addressed PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kenrick Yap <[email protected]>
  • Loading branch information
kenrickyap committed Jan 10, 2025
1 parent 9fea606 commit fbc54bc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

@ExtendWith(MockitoExtension.class)
public class JsonFunctionsTest {
private static final ExprValue JsonNestedObject =
ExprValueUtils.stringValue("{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}");
private static final ExprValue JsonObject =
ExprValueUtils.stringValue("{\"a\":\"1\",\"b\":\"2\"}");
private static final ExprValue JsonArray = ExprValueUtils.stringValue("[1, 2, 3, 4]");
Expand All @@ -36,6 +38,7 @@ public void json_valid_returns_false() {

@Test
public void json_valid_returns_true() {
assertEquals(LITERAL_TRUE, execute(JsonNestedObject));
assertEquals(LITERAL_TRUE, execute(JsonObject));
assertEquals(LITERAL_TRUE, execute(JsonArray));
assertEquals(LITERAL_TRUE, execute(JsonScalarString));
Expand Down
21 changes: 11 additions & 10 deletions docs/user/ppl/functions/json.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
====================
IP Address Functions
JSON Functions
====================

.. rubric:: Table of contents
Expand All @@ -24,12 +24,13 @@ Example::

> source=json_test | eval is_valid = json_valid(json_string) | fields test_name, json_string, is_valid
fetched rows / total rows = 4/4
+---------------------+------------------------------+----------+
| test_name | json_string | is_valid |
|---------------------|------------------------------|----------|
| json object | {"a":"1","b":"2"} | True |
| json array | [1, 2, 3, 4] | True |
| json scalar string | "abc" | True |
| json empty string | | True |
| json invalid object | {"invalid":"json", "string"} | False |
+---------------------+------------------------------+----------+
+---------------------+---------------------------------+----------+
| test_name | json_string | is_valid |
|---------------------|---------------------------------|----------|
| json nested object | {"a":"1","b":{"c":"2","d":"3"}} | True |
| json object | {"a":"1","b":"2"} | True |
| json array | [1, 2, 3, 4] | True |
| json scalar string | "abc" | True |
| json empty string | | True |
| json invalid object | {"invalid":"json", "string"} | False |
+---------------------+---------------------------------+----------+
1 change: 1 addition & 0 deletions doctest/test_data/json_test.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{"test_name":"json nested object", "json_string":"{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}"}
{"test_name":"json object", "json_string":"{\"a\":\"1\",\"b\":\"2\"}"}
{"test_name":"json array", "json_string":"[1, 2, 3, 4]"}
{"test_name":"json scalar string", "json_string":"\"abc\""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void test_json_valid() throws IOException {
verifySchema(result, schema("test_name", null, "string"));
verifyDataRows(
result,
rows("json nested object"),
rows("json object"),
rows("json array"),
rows("json scalar string"),
Expand Down
2 changes: 2 additions & 0 deletions integ-test/src/test/resources/json_test.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{"index":{"_id":"0"}}
{"test_name":"json nested object", "json_string":"{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}"}
{"index":{"_id":"1"}}
{"test_name":"json object", "json_string":"{\"a\":\"1\",\"b\":\"2\"}"}
{"index":{"_id":"2"}}
Expand Down

0 comments on commit fbc54bc

Please sign in to comment.