json (DataStreamReader)

Laadt een JSON-bestandsstroom en retourneert de resultaten als een DataFrame. JSON-lijnen (JSON met newline-scheidingstekens) worden standaard ondersteund. Voor JSON met één record per bestand stelt u de multiLine optie in op true. Als schema dit niet is opgegeven, wordt het invoerschema afgeleid van de gegevens.

Syntaxis

json(path, schema=None, **options)

Parameterwaarden

Kenmerk Typ Beschrijving
path str Pad naar de JSON-gegevensset.
schema StructType of str, optioneel Schema als een StructType- of DDL-opgemaakte tekenreeks (bijvoorbeeld col0 INT, col1 DOUBLE).

Retouren

DataFrame

Examples

Een stream laden vanuit een tijdelijk JSON-bestand:

import tempfile
import time
with tempfile.TemporaryDirectory(prefix="json") as d:
    spark.createDataFrame(
        [(100, "Hyukjin Kwon"),], ["age", "name"]
    ).write.mode("overwrite").format("json").save(d)
    q = spark.readStream.schema(
        "age INT, name STRING"
    ).json(d).writeStream.format("console").start()
    time.sleep(3)
    q.stop()