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.

Added in version 4.0.0.

Parameters:
colColumn or str

a column or column name JSON formatted strings. A column that evaluates to a string.

Returns:
Column

a new column of VariantType. Returns a column that evaluates to a variant.

Examples

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