# JSON CSV XML YAML TOML Data Format Converter (`chun_yung_lo/json-csv-xml-yaml-toml-converter`) Actor

Convert text between JSON, JSON Lines, CSV, XML, YAML and TOML in one call. Paste the data, pick the source and target format, get the converted text. Also works as an MCP tool for AI agents.

- **URL**: https://apify.com/chun_yung_lo/json-csv-xml-yaml-toml-converter.md
- **Developed by:** [Chun-Yung Yong Lo](https://apify.com/chun_yung_lo) (community)
- **Categories:** Developer tools, Automation, MCP servers
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 data converteds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## JSON, CSV, XML, YAML, TOML Data Format Converter

Convert text between **JSON, JSON Lines, CSV, XML, YAML and TOML** in a single call. Paste your data, choose the source and target format, and get the converted text back. No code, no setup. The Actor also runs as an MCP server, so AI agents can call it as a tool.

### What it does

- Reads JSON, JSON Lines, CSV, XML, YAML or TOML.
- Writes any of those formats.
- Nested JSON/YAML/XML is flattened for CSV output using dotted column names (for example `address.city`). Arrays inside a row become a compact JSON string in that cell.
- XML attributes appear as keys starting with `@`, and element text next to attributes appears as `#text`.
- CSV output unwraps a single-key wrapper (for example an XML `<root><item>...</item></root>`) so repeated items become rows.
- Optional type inference when reading CSV (numbers and true/false).
- Clear error messages when the input cannot be parsed.

Everything runs offline on the text you provide. Nothing is fetched from the web.

### Input example

```json
{
  "data": "[{\"name\":\"Ann\",\"age\":30},{\"name\":\"Bob\",\"age\":25}]",
  "fromFormat": "json",
  "toFormat": "csv"
}
```

Fields: `data`, `fromFormat`, `toFormat` (required); `indent` (0-8, JSON output, 0 = compact); `csvDelimiter` (comma, semicolon, tab, pipe); `inferTypes` (CSV input); `xmlRootName` (wrapper element for XML output).

### Output example

```json
{
  "output": "name,age\nAnn,30\nBob,25",
  "fromFormat": "json",
  "toFormat": "csv",
  "records": 2,
  "characters": 22
}
```

### Pricing

US$0.002 per conversion (one run = one conversion).

### Limits

- Input up to 2,000,000 characters.
- CSV is flat by nature, so converting nested data to CSV is lossy for arrays (they become JSON strings) and CSV cannot be converted back to the original nesting.
- TOML output requires an object (or a list, which is wrapped under `items`) and cannot represent null values.
- XML needs a single root element; if your data has none, it is wrapped in the element named by `xmlRootName`.
- XML entity declarations are rejected for safety.
- Binary documents (PDF, images, OCR) and web page extraction are not supported.

### Credits

Built on open-source libraries:

- [xmltodict](https://github.com/martinblech/xmltodict) (MIT)
- [PyYAML](https://github.com/yaml/pyyaml) (MIT)
- [tomli](https://github.com/hukkin/tomli) and [tomli-w](https://github.com/hukkin/tomli-w) (MIT)

# Actor input Schema

## `data` (type: `string`):

The text to convert (max 2,000,000 characters).

## `fromFormat` (type: `string`):

Format of the text in the data field.

## `toFormat` (type: `string`):

Format to convert the data into.

## `indent` (type: `integer`):

Spaces of indentation for JSON output (0 to 8). Use 0 for compact single-line JSON.

## `csvDelimiter` (type: `string`):

Delimiter used when reading or writing CSV.

## `inferTypes` (type: `boolean`):

When reading CSV, turn values like 30, 1.5, true and false into numbers and booleans instead of strings.

## `xmlRootName` (type: `string`):

Name of the wrapper element used when the data has no single root (XML output only).

## Actor input object example

```json
{
  "data": "[{\"name\":\"Ann\",\"age\":30},{\"name\":\"Bob\",\"age\":25}]",
  "fromFormat": "json",
  "toFormat": "csv",
  "indent": 2,
  "csvDelimiter": "comma",
  "inferTypes": false,
  "xmlRootName": "root"
}
```

# Actor output Schema

## `results` (type: `string`):

One row per processed input

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "data": "[{\"name\":\"Ann\",\"age\":30},{\"name\":\"Bob\",\"age\":25}]"
};

// Run the Actor and wait for it to finish
const run = await client.actor("chun_yung_lo/json-csv-xml-yaml-toml-converter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "data": "[{\"name\":\"Ann\",\"age\":30},{\"name\":\"Bob\",\"age\":25}]" }

# Run the Actor and wait for it to finish
run = client.actor("chun_yung_lo/json-csv-xml-yaml-toml-converter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "data": "[{\\"name\\":\\"Ann\\",\\"age\\":30},{\\"name\\":\\"Bob\\",\\"age\\":25}]"
}' |
apify call chun_yung_lo/json-csv-xml-yaml-toml-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,chun_yung_lo/json-csv-xml-yaml-toml-converter"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/jmepjrga49xLmKXRF/builds/qgfg847glwKooknnQ/openapi.json
