Skip to main content

toJSON

Converts a DataFrame into a RDD of string or DataFrame.

Syntax

toJSON(use_unicode: bool = True)

Parameters

Parameter

Type

Description

use_unicode

bool, optional, default True

Whether to convert to unicode or not. Note that this argument is disallowed in Spark Connect mode.

Returns

:class:RDD (in Classic mode) or `:class:`DataFrame (in connect mode)

Examples

Python
df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
df.toJSON().first()
# '{"age":2,"name":"Alice"}'