# JSON to CSV

`json-to-csv` · version 1.0.0 · JSON & JSONL · free, no key needed

Serialize string-valued JSON rows to CSV using explicit ordered columns.

**Use when you need to: json to csv · convert json rows to csv · serialize json objects as csv.**

## Supported

- json to csv
- convert json rows to csv
- serialize json objects as csv

## Not supported

- infer columns
- coerce values
- flatten nested json
- stream rows
- read files
- fetch urls

## Behavior

- columns supplies the non-empty, unique header names and their output order.
- Every row must contain exactly those own keys with string values.
- Values are not coerced and nested values are rejected.
- Row order is retained and an empty rows array produces header-only CSV.
- Prototype-like column names are handled as ordinary own JSON keys.
- The first column name may not begin with U+FEFF because it is ambiguous with a CSV byte-order mark.

## Input

- `columns` (array of string, required): min items 1; max items 256; each min length 1
- `rows` (array of object, required): max items 5000

## Output

- string

## Limits

- max input bytes: 256000
- max data rows: 5000
- max columns: 256
- max header name bytes: 256
- max output bytes: 256000

## Example

Request input:

```json
{
  "columns": [
    "name",
    "note"
  ],
  "rows": [
    {
      "name": "Ada",
      "note": "hello, world"
    }
  ]
}
```

Response:

```json
{
  "result": "name,note\nAda,\"hello, world\"\n"
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "json-to-csv",
  "version": "1.0.0",
  "input": {
    "columns": [
      "name",
      "note"
    ],
    "rows": [
      {
        "name": "Ada",
        "note": "hello, world"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/json-to-csv/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"columns":["name","note"],"rows":[{"name":"Ada","note":"hello, world"}]}'
```

The machine-readable contract is at [/v1/tools/json-to-csv/versions/1.0.0](/v1/tools/json-to-csv/versions/1.0.0).

### CLI

```sh
node cli.mjs run json-to-csv 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Array to JSONL](/tools/array-to-jsonl): Serialize an array of JSON-safe values as JSON Lines text.
- [JSON array index by](/tools/json-array-index-by): Convert an array of objects into a single object indexed by a specific key.
- [JSONL to array](/tools/jsonl-to-array): Parse strict JSON Lines text into an array of JSON-safe values.
- [JSON array distinct by](/tools/json-array-distinct-by): Deduplicate a JSON array of objects based on specific keys.
- [JSON array filter equals](/tools/json-array-filter-equals): Filter JSON array objects where a key equals a specific value.
- [JSON array group by](/tools/json-array-group-by): Group an array of JSON objects by exact keys.
