pyspark.sql.functions.json_tuple¶
-
pyspark.sql.functions.
json_tuple
(col: ColumnOrName, *fields: str) → pyspark.sql.column.Column[source]¶ 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.
- Parameters
- col
Column
or str string column in json format
- fieldsstr
a field or fields to extract
- col
- Returns
Column
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)]