Initializing playground…
← Back to roadmap

📄 readJson & toJson — Interactive Playground

Parse JSON text into a DataFrame with readJson() and serialize back with toJson(). Mirrors pandas read_json() and pandas DataFrame.to_json(), supporting five orient formats.
Edit any code block below and press ▶ Run (or Ctrl+Enter) to execute it live in your browser.

1 · Parse records JSON (default)

The "records" orient is an array of row objects — the most natural JSON format for tabular data. Auto-detected when the input is a JSON array.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

2 · Split orient

The "split" orient stores columns, index, and data separately — compact and lossless. Auto-detected when the root object contains "columns" and "data" keys.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

3 · Index orient

The "index" orient uses row-index labels as keys, each mapping to a record of column values.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

4 · Columns orient

The "columns" orient uses column names as keys, each mapping to an object of index-label → value pairs. Useful for column-major storage.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

5 · Values orient

The "values" orient is a plain 2-D array — no index or column labels. Columns are auto-named "0", "1", etc.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

6 · Serialize with toJson()

toJson(df, options) serializes a DataFrame to a JSON string. Choose any orient and optionally pretty-print with indent.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

7 · Round-trip

A DataFrame serialized with toJson can be reconstructed with readJson without data loss.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

API Reference

Parse JSON into a DataFrame or serialize a DataFrame back to JSON. Five orient formats are supported: records, split, index, columns, and values.

// Parse JSON → DataFrame
readJson(json: string, options?: {
  orient?: "records" | "split" | "index" | "columns" | "values",
}): DataFrame

// Serialize DataFrame → JSON
toJson(df: DataFrame, options?: {
  orient?: "records" | "split" | "index" | "columns" | "values",
  indent?: number,
}): string