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.

Parameters
colColumn or str

string column in json format

fieldsstr

fields to extract

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)]