# JSON

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

Kotlin DataFrame supports reading from and writing to JSON files.

API reference: [readJson](https://kotlin.github.io/dataframe/api-docs/dataframe-json/org.jetbrains.kotlinx.dataframe.io/read-json.html), [writeJson](https://kotlin.github.io/dataframe/api-docs/dataframe-json/org.jetbrains.kotlinx.dataframe.io/write-json.html), [dataframe-json module](https://kotlin.github.io/dataframe/api-docs/dataframe-json/index.html)

Requires the [dataframe-json module](modules.html#dataframe-json), which is included by default in the general [dataframe](modules.html#dataframe-general) artifact and in [%use dataframe](setupkotlinnotebook.html#integrate-kotlin-dataframe) for Kotlin Notebook.

> **Note:**
> Kotlin DataFrame is suitable only for working with table-like structured JSON — a list of objects where each object represents a row and all objects share the same structure.
>
>
>
> Experimental support for [OpenAPI JSON schemas](openapi.html) is also available.

## Read

You can read a [DataFrame](dataframe.html) or [DataRow](datarow.html) from a JSON file (via a file path or URL) using the [readJson()](read.html#read-from-json) method:

```KOTLIN
val df = DataFrame.readJson("example.json")
```

```KOTLIN
val df = DataFrame.readJson("https://kotlin.github.io/dataframe/resources/example.json")
```

A JSON `null` is read as `null`, so the corresponding column becomes nullable. A property that some records simply don't have is read as `null` as well — a [DataFrame](dataframe.html) is rectangular, so every row needs a value in every column.

This also holds for array columns: `[null, [123], []]` is read as a `List<Int>?` column holding `null`, `[123]`, and an empty list.

JSON elements that aren't objects have no property name to use as a column name, so they're read into the special [value and array columns](read.html#value-and-array-columns). The same special columns are also used to resolve [type clashes](read.html#manage-type-clashes) when the same property contains values of different shapes across records.

## Write

You can write a [DataFrame](dataframe.html) to a JSON file using the [writeJson()](write.html#writing-to-json) method:

```KOTLIN
df.writeJson("example.json")
```

A [DataFrame](dataframe.html) read from JSON with a top-level type clash is written back to its original form; see [writing to JSON](write.html#writing-to-json) for the details and for the cases that don't round-trip.

