pyspark.sql.functions.get_json_object¶
-
pyspark.sql.functions.
get_json_object
(col, path)[source]¶ Extracts json object from a json string based on json path specified, and returns json string of the extracted json object. It will return null if the input json string is invalid.
New in version 1.6.0.
- Parameters
- col
Column
or str string column in json format
- pathstr
path to the json object to extract
- col
Examples
>>> 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)]