Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Parses a JSON string and infers its schema in DDL format.
Syntax
from pyspark.sql import functions as sf
sf.schema_of_json(json, options=None)
Parameters
| Parameter | Type | Description |
|---|---|---|
json |
pyspark.sql.Column or str |
A JSON string or a foldable string column containing a JSON string. |
options |
dict, optional | Options to control parsing. Accepts the same options as the JSON datasource. |
Returns
pyspark.sql.Column: a string representation of a StructType parsed from given JSON.
Examples
import pyspark.sql.functions as sf
parsed1 = sf.schema_of_json(sf.lit('{"a": 0}'))
parsed2 = sf.schema_of_json('{a: 1}', {'allowUnquotedFieldNames':'true'})
spark.range(1).select(parsed1, parsed2).show()
+------------------------+----------------------+
|schema_of_json({"a": 0})|schema_of_json({a: 1})|
+------------------------+----------------------+
| STRUCT<a: BIGINT>| STRUCT<a: BIGINT>|
+------------------------+----------------------+