### Question:
JsonExtractStringKudf implements Kudf { @Override public Object evaluate(Object... args) { if (args.length != 2) { throw new KsqlFunctionException("getStringFromJson udf should have two input arguments:" + " JSON document and JSON path."); } ensureInitialized(args); JsonNode currentNode = parseJsonDoc(args[0]); for (String token : tokens) { if (currentNode instanceof ArrayNode) { try { final int index = Integer.parseInt(token); currentNode = currentNode.get(index); } catch (NumberFormatException e) { return null; } } else { currentNode = currentNode.get(token); } if (currentNode == null) { return null; } } if (currentNode.isTextual()) { return currentNode.asText(); } else { return currentNode.toString(); } }  @Override Object evaluate(Object... args);  }### Answer:
@Test public void shouldExtractJsonField() { final Object result = udf.evaluate(JSON_DOC, "$.thing1.thing2"); assertThat(result, is("hello")); }
@Test public void shouldExtractJsonDoc() { final Object result = udf.evaluate(JSON_DOC, "$.thing1"); assertThat(result, is("{\"thing2\":\"hello\"}")); }
@Test public void shouldExtractWholeJsonDoc() { final Object result = udf.evaluate(JSON_DOC, "$"); assertThat(result, is(JSON_DOC)); }
@Test public void shouldExtractJsonArrayField() { final Object result = udf.evaluate(JSON_DOC, "$.array.1"); assertThat(result, is("102")); }
@Test public void shouldReturnNullIfNodeNotFound() { final Object result = udf.evaluate(JSON_DOC, "$.will.not.find.me"); assertThat(result, is(nullValue())); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfTooFewParameters() { udf.evaluate(JSON_DOC); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfTooManyParameters() { udf.evaluate(JSON_DOC, "$.thing1", "extra"); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowOnInvalidJsonDoc() { udf.evaluate("this is NOT a JSON doc", "$.thing1"); }