---
title: toJSON
description: "DataFrame.toJSON method in PySpark: Converts a DataFrame into a RDD of string or DataFrame."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/toJSON
---

# 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"}'
```
