pyspark.sql.functions.
json_tuple
Creates a new row for a json column according to the given field names.
New in version 1.6.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
string column in json format
a field or fields to extract
a new row for each given field value from json object
Examples
>>> data = [("1", '''{"f1": "value1", "f2": "value2"}'''), ("2", '''{"f1": "value12"}''')] >>> df = spark.createDataFrame(data, ("key", "jstring")) >>> df.select(df.key, json_tuple(df.jstring, 'f1', 'f2')).collect() [Row(key='1', c0='value1', c1='value2'), Row(key='2', c0='value12', c1=None)]