pyspark.sql.functions.parse_json#

pyspark.sql.functions.parse_json(col)[source]#

Parses a column containing a JSON string into a VariantType. Throws exception if a string represents an invalid JSON value.

New in version 4.0.0.

Parameters
colColumn or str

a column or column name JSON formatted strings

Returns
Column

a new column of VariantType.

Examples

>>> df = spark.createDataFrame([ {'json': '''{ "a" : 1 }'''} ])
>>> df.select(to_json(parse_json(df.json))).collect()
[Row(to_json(parse_json(json))='{"a":1}')]