diff --git a/src/main/java/com/snowflake/snowpark_java/types/Variant.java b/src/main/java/com/snowflake/snowpark_java/types/Variant.java index ac14e0eb..75e993ad 100644 --- a/src/main/java/com/snowflake/snowpark_java/types/Variant.java +++ b/src/main/java/com/snowflake/snowpark_java/types/Variant.java @@ -377,9 +377,20 @@ public String asJsonString() { } /** - * Converts the variant as valid JsonNode. + * Converts the variant as valid JsonNode. This function allows to read the JSON object directly + * rather parsing it as String and then extract the desired value * - * @return A valid json Node + *
{@code - to get the first value from array for key "a"
+   *
+   * Variant jv = new Variant("{\"a\": [1, 2], \"b\": \"c\"}");
+   * JsonNode jNode = jv.asJsonNode();
+   * System.out.println(jNode.get("a").get(0));
+   *
+   * output
+   * 1
+   * }
+ * + * @return A valid JsonNode * @since 1.14.0 */ public JsonNode asJsonNode() { diff --git a/src/main/scala/com/snowflake/snowpark/types/Variant.scala b/src/main/scala/com/snowflake/snowpark/types/Variant.scala index b74a6ebb..c3981402 100644 --- a/src/main/scala/com/snowflake/snowpark/types/Variant.scala +++ b/src/main/scala/com/snowflake/snowpark/types/Variant.scala @@ -385,7 +385,17 @@ class Variant private[snowpark] ( /** * Converts the variant as valid JsonNode + * This function allows to read the JSON object directly rather parsing it as String + * and then extract the desired value + * Example - to get the first value from array for key "a" + * {{{ + * val sv = new Variant("{\"a\": [1, 2], \"b\": 3, \"c\": \"xyz\"}") + * println(sv.asMap.get("a").get.asJsonNode().get(0)) * + * output + * 1 + * + * }}} * @since 1.14.0 */ def asJsonNode(): JsonNode = { diff --git a/src/test/java/com/snowflake/snowpark_test/JavaVariantSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaVariantSuite.java index f20e9dd2..93adb47b 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaVariantSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaVariantSuite.java @@ -371,7 +371,6 @@ public void equalsAndToString() { public void javaJsonNodeVariantConverter() throws IllegalArgumentException { Variant jv = new Variant("{\"a\": [1, 2], \"b\": \"c\"}"); JsonNode jNode = jv.asJsonNode(); - assert (jNode.get("a").isArray()); assert (jNode.get("b").asText().equals("c")); }