Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gmahadevan committed Aug 28, 2024
1 parent 6f35e5f commit dbde5dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/snowflake/snowpark_java/types/Variant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <pre>{@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
* }</pre>
*
* @return A valid JsonNode
* @since 1.14.0
*/
public JsonNode asJsonNode() {
Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/com/snowflake/snowpark/types/Variant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down

0 comments on commit dbde5dd

Please sign in to comment.