panbingkun commented on code in PR #49875: URL: https://github.com/apache/spark/pull/49875#discussion_r1958974063
########## python/pyspark/sql/functions/builtin.py: ########## @@ -20115,11 +20115,47 @@ def get_json_object(col: "ColumnOrName", path: str) -> Column: Examples -------- + Example 1: Extract a json object from json string + + >>> import pyspark.sql.functions as sf >>> 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)] + >>> extracted1 = sf.get_json_object(df.jstring, '$.f1').alias("c0") + >>> extracted2 = sf.get_json_object(df.jstring, '$.f2').alias("c1") + >>> df.select(df.key, extracted1, extracted2).show() Review Comment: df.select(df.key, sf.get_json_object(df.jstring, '$.f1').alias("c0"), sf.get_json_object(df.jstring, '$.f2').alias("c1")).show() -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org