# Data Format Converter: JSON, XML, YAML, CSV and TSV (`examsens.ai/data-format-converter`) Actor

Converts JSON, JSON Lines, XML, YAML, CSV and TSV files, URLs, pasted text or Apify datasets to any of the other formats, with nested object flattening, record path selection and type detection. Returns a download link for each file.

- **URL**: https://apify.com/examsens.ai/data-format-converter.md
- **Developed by:** [Ed Rayyis](https://apify.com/examsens.ai) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.80 / 1,000 document converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-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

## Data Format Converter: JSON, XML, YAML, CSV and TSV

Convert data files between JSON, JSON Lines, XML, YAML, CSV and TSV. Give it file URLs, pasted text or the IDs of Apify datasets, pick the output format, and get one converted file per source with a download link.

### What it does

- Reads JSON, JSON Lines, XML, YAML, CSV and TSV, and writes any of them.
- Detects the input format from the file extension, the content type and the content. You can also set it.
- For CSV, TSV and JSON Lines output, it finds the list of records for you. An RSS feed becomes one row per `rss.channel.item`, and a GitHub workflow becomes one row per step. Set a record path such as `data.results` to choose another part.
- Flattens nested objects into path columns such as `address.city` and `company.name`. Lists inside a record become one column per item (`tags.0`, `tags.1`), one cell joined with semicolons, or one cell of JSON text.
- Keeps only the columns you list, in your order.
- Rebuilds nested objects and lists from CSV path columns, so `address.city` and `tags.0` go back to an object and a list in JSON or YAML.
- Detects numbers, `true`, `false` and null in CSV and XML. Values with a leading zero (`007`, `01234`) stay text, and so do values that would change when read as a number (`2.10`, `1e5`).
- Reads YAML booleans the YAML 1.2 way: only `true` and `false`. A key such as `on:` in a workflow file stays the text `on`.
- Keeps XML attributes under keys that start with `@`, and element text next to attributes under `#text`. Keys that are not valid XML names are made valid when writing XML.
- Reads Apify datasets in your account, so you can turn a scraper's results into XML or YAML.

### Input

- File URLs: public URLs, up to 50 MB each
- Pasted data: one document per entry
- Apify dataset IDs
- Input format (default auto detect) and output format (default CSV)
- Record path (optional dot path)
- Tabular output: flatten nested objects (default on), path separator (default `.`), lists inside records, columns to keep, header row, CSV output delimiter
- CSV and XML input: input delimiter (default detect), header row, detect numbers and booleans, values read as null, rebuild nested objects
- JSON, XML and YAML output: indent, XML root and item element names, XML attribute prefix

### Output

Each converted file goes to the run's key value store. The dataset holds one item per source with `source`, `ok`, `inputFormat`, `outputFormat`, `recordPath`, `recordCount`, `columnCount`, `columns`, `outputKey`, `outputUrl` (download link), `outputBytes` and a `preview` of the first 1,500 characters. A source that fails gets `ok: false` and an `error` such as `HTTP 404`, a JSON syntax error with its line and column, or `Dataset was not found`. The other sources still convert.

### Pricing

Pay per event: one event per source converted. A source that fails is not charged. The run stops when it reaches the maximum charge you set.

### Scope and conduct

Only the URLs you list are downloaded, once each. XML entity declarations are refused, so a file cannot expand itself or read local files. Nothing is stored beyond the run's own storage.

### Support

Questions and problems: the Issues tab on this page. Replies are written by an AI assistant on behalf of the developer and reviewed by the developer.

# Actor input Schema

## `urls` (type: `array`):

Public URLs of JSON, JSON Lines, XML, YAML, CSV or TSV files. Each one becomes one output file. Up to 50 MB each.

## `texts` (type: `array`):

Data pasted as text, one document per entry. Each one becomes one output file.

## `datasetIds` (type: `array`):

Apify datasets in your account to convert, for example to turn a scraper's results into XML or YAML. Pick them, or give their IDs.

## `inputFormat` (type: `string`):

Format of the sources. Auto detects it from the file extension, the content type and the content itself.

## `outputFormat` (type: `string`):

Format to write.

## `recordPath` (type: `string`):

Dot path to the part of the document to convert, such as rss.channel.item or data.results. Leave empty: for CSV, TSV and JSON Lines output the first list of records is found for you; for other output the whole document is converted.

## `flatten` (type: `boolean`):

For CSV and TSV output: turn nested objects into path columns such as address.city. When off, nested values are written as JSON text in one cell.

## `keySeparator` (type: `string`):

Text placed between the parts of a flattened column name, and split on when rebuilding nested objects from CSV.

## `arrayMode` (type: `string`):

How a list inside a record is written to CSV: one column per item (tags.0, tags.1), the items joined with a semicolon in one cell, or the list as JSON text in one cell.

## `columns` (type: `array`):

For CSV and TSV output: the column names to write, in this order. Leave empty to write every column.

## `includeHeader` (type: `boolean`):

Write the column names as the first row of CSV and TSV output.

## `csvOutputDelimiter` (type: `string`):

Column delimiter for CSV output, such as a comma or a semicolon.

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

Column delimiter of CSV input. Leave empty to detect comma, semicolon, tab or pipe.

## `csvHasHeader` (type: `boolean`):

Use the first CSV row as field names. When off, fields are named column_1, column_2 and so on.

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

Turn CSV and XML text values into numbers, true or false, and null. Values with a leading zero, such as 007 or ZIP codes, stay text.

## `nullTokens` (type: `array`):

CSV and XML values, compared without case, that become null when type detection is on.

## `unflatten` (type: `boolean`):

Turn CSV columns such as address.city back into nested objects, and columns such as tags.0 and tags.1 into lists, using the path separator.

## `pretty` (type: `boolean`):

Indent JSON and XML output for reading.

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

Root element name used when the data has no single root, such as a list of records.

## `xmlItemName` (type: `string`):

Element name for each record of a list.

## `attributePrefix` (type: `string`):

Keys starting with this text are XML attributes, both when reading and when writing XML. Element text next to attributes is kept under #text.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://raw.githubusercontent.com/datasets/country-codes/main/data/country-codes.csv"
    }
  ],
  "inputFormat": "auto",
  "outputFormat": "csv",
  "flatten": true,
  "keySeparator": ".",
  "arrayMode": "index",
  "includeHeader": true,
  "csvOutputDelimiter": ",",
  "csvHasHeader": true,
  "inferTypes": true,
  "nullTokens": [
    "",
    "null",
    "NA",
    "N/A"
  ],
  "unflatten": false,
  "pretty": true,
  "xmlRootName": "root",
  "xmlItemName": "item",
  "attributePrefix": "@"
}
```

# Actor output Schema

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

No description

# 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 = {
    "urls": [
        {
            "url": "https://raw.githubusercontent.com/datasets/country-codes/main/data/country-codes.csv"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("examsens.ai/data-format-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 = { "urls": [{ "url": "https://raw.githubusercontent.com/datasets/country-codes/main/data/country-codes.csv" }] }

# Run the Actor and wait for it to finish
run = client.actor("examsens.ai/data-format-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 '{
  "urls": [
    {
      "url": "https://raw.githubusercontent.com/datasets/country-codes/main/data/country-codes.csv"
    }
  ]
}' |
apify call examsens.ai/data-format-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,examsens.ai/data-format-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/cs9pKtzPFhdSydLfu/builds/gqGUVtDBgnut0wwPc/openapi.json
