You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "fusheng9399 (via GitHub)" <gi...@apache.org> on 2025/02/12 06:45:07 UTC
Re: [PR] [SPARK-51152][SQL] Add richer examples for the get_json_object function [spark]
fusheng9399 commented on code in PR #49875:
URL: https://github.com/apache/spark/pull/49875#discussion_r1952069454
##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -20115,11 +20115,24 @@ def get_json_object(col: "ColumnOrName", path: str) -> Column:
Examples
--------
+ Example1: Get json object from json object
+
>>> data = [("1", '''{"f1": "value1", "f2": "value2"}'''), ("2", '''{"f1": "value12"}''')]
>>> df = spark.createDataFrame(data, ("key", "jstring"))
>>> df.select(df.key, get_json_object(df.jstring, '$.f1').alias("c0"), \\
... get_json_object(df.jstring, '$.f2').alias("c1") ).collect()
[Row(key='1', c0='value1', c1='value2'), Row(key='2', c0='value12', c1=None)]
+
+ Example2: Get json object from json array object
+
+ data = [("1", '''[{"f1": "value1", "f2": "value2"},{"f1": "value3", "f2": "value4"}]'''), ("2", '''[{"f1": "value12"},{"f1": "value13"}]''')]
Review Comment:
okļ¼done~
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org