DataStreamReader.
json
Loads a JSON file stream and returns the results as a DataFrame.
DataFrame
JSON Lines (newline-delimited JSON) is supported by default. For JSON (one record per file), set the multiLine parameter to true.
multiLine
true
If the schema parameter is not specified, this function goes through the input once to determine the input schema.
schema
New in version 2.0.0.
string represents path to the JSON dataset, or RDD of Strings storing JSON objects.
pyspark.sql.types.StructType
an optional pyspark.sql.types.StructType for the input schema or a DDL-formatted string (For example col0 INT, col1 DOUBLE).
col0 INT, col1 DOUBLE
For the extra options, refer to Data Source Option in the version you use.
Notes
This API is evolving.
Examples
Load a data stream from a temporary JSON file.
>>> import tempfile >>> import time >>> with tempfile.TemporaryDirectory() as d: ... # Write a temporary JSON file to read it. ... spark.createDataFrame( ... [(100, "Hyukjin Kwon"),], ["age", "name"] ... ).write.mode("overwrite").format("json").save(d) ... ... # Start a streaming query to read the JSON file. ... q = spark.readStream.schema( ... "age INT, name STRING" ... ).json(d).writeStream.format("console").start() ... time.sleep(3) ... q.stop()