Data Formats

Convert structured data between JSON, CSV, XML, YAML, and TOML — in any direction. Two endpoints cover both workflows: a JSON response for inline data, and a direct streaming file download.

Base URL

https://convert.toolkitapi.io

Endpoints

Method Endpoint Purpose
POST /v1/convert/data Convert a body payload → JSON response
GET /v1/convert/data Convert from a URL or inline query → streamed file download

Authentication is via the X-API-Key header (or Authorization: Bearer).


Supported conversions

Any pair among json, csv, xml, yaml, toml is supported. A few direction-specific rules apply:

  • JSON → CSV requires an array of objects. Nested objects are flattened with dot notation (e.g. address.city).
  • JSON → TOML requires a top-level object (dict), not an array.
  • CSV → JSON emits an array of objects (with header) or arrays (without header).

GET /v1/convert/data

Stream a converted file download. Provide url or content as the source.

Query parameters

Parameter Type Required Description
from_format string yes Source format: json, csv, xml, yaml, toml
to_format string yes Target format: json, csv, xml, yaml, toml
url string one of url/content Public URL to fetch source data from
content string one of url/content Inline source data
delimiter string (1 char) no CSV delimiter (auto-detected if omitted)
include_header boolean no Include a header row in CSV output (default true)
has_header boolean no Treat first CSV input row as a header (default true)
skip_rows integer ≥ 0 no Number of initial rows to skip in CSV input (default 0)
root_element string no Root element name for XML output (default root)
pretty boolean no Pretty-print XML output (default true)
strip_namespaces boolean no Strip XML namespace prefixes (default false)
flow_style boolean no Use YAML flow (inline) style (default false)
filename string ≤ 255 no Download filename (default output)

Response

200 OK with a Content-Type matching the target format and a Content-Disposition: attachment header.

Example — curl (JSON → YAML)

curl -L -G "https://convert.toolkitapi.io/v1/convert/data" \
  -H "X-API-Key: $CONVERT_API_KEY" \
  --data-urlencode 'content={"name":"test","value":42}' \
  --data-urlencode 'from_format=json' \
  --data-urlencode 'to_format=yaml' \
  -o output.yaml

Example — Python (remote CSV → JSON file)

import httpx

resp = httpx.get(
    "https://convert.toolkitapi.io/v1/convert/data",
    headers={"X-API-Key": CONVERT_API_KEY},
    params={
        "url": "https://example.com/products.csv",
        "from_format": "csv",
        "to_format": "json",
        "has_header": True,
        "filename": "products.json",
    },
)
resp.raise_for_status()
open("products.json", "wb").write(resp.content)

Example — JavaScript (inline JSON → CSV)

const params = new URLSearchParams({
  content: JSON.stringify([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]),
  from_format: "json",
  to_format: "csv",
});

const resp = await fetch(
  `https://convert.toolkitapi.io/v1/convert/data?${params}`,
  { headers: { "X-API-Key": process.env.CONVERT_API_KEY } },
);
const csv = await resp.text();
console.log(csv);
// id,name
// 1,Alice
// 2,Bob

Note

This same conversion is also available through the Dev toolkit at dev.toolkitapi.io/v1/convert/data.


POST /v1/convert/data

Convert a JSON request body and return the result as JSON. All conversion logic is shared with the GET endpoint; only the transport differs.

Request body

Field Type Description
from_format string Source format: json, csv, xml, yaml, toml
to_format string Target format: json, csv, xml, yaml, toml
data any Inline data — a JSON value, or a raw string for CSV/XML/YAML/TOML
url string Public URL to fetch source data from (alternative to data)
delimiter string CSV column delimiter (auto-detected if omitted)
include_header boolean Include header row in CSV output
has_header boolean Whether the first CSV row is a header
skip_rows integer Number of initial rows to skip in CSV input
root_element string Root element name for XML output (default root)
pretty boolean Pretty-print XML output
strip_namespaces boolean Strip XML namespace prefixes on input
force_list array XML element names to always wrap in a JSON array
flow_style boolean Use YAML inline (flow) style
document_index integer Select a specific YAML document index (0-based)

Provide either data or url — supplying both, or neither, returns 422.

Response fields

Field Type Description
success boolean true on success
from_format string Source format used
to_format string Target format used
result string | object The converted content
metadata object Format-specific stats such as rows, columns, elements_count

Example — curl (JSON → YAML)

curl -X POST https://convert.toolkitapi.io/v1/convert/data \
  -H "X-API-Key: $CONVERT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from_format": "json",
    "to_format": "yaml",
    "data": {"name": "test", "value": 42}
  }'
{
  "success": true,
  "from_format": "json",
  "to_format": "yaml",
  "result": "name: test\nvalue: 42\n",
  "metadata": {}
}

Example — Python (JSON array → CSV, nested fields flattened)

import httpx

resp = httpx.post(
    "https://convert.toolkitapi.io/v1/convert/data",
    headers={"X-API-Key": CONVERT_API_KEY},
    json={
        "from_format": "json",
        "to_format": "csv",
        "data": [
            {"id": 1, "name": "Alice", "address": {"city": "London"}},
            {"id": 2, "name": "Bob", "address": {"city": "Paris"}},
        ],
    },
)
print(resp.json()["result"])
# id,name,address.city
# 1,Alice,London
# 2,Bob,Paris

Example — JavaScript (XML → JSON)

const resp = await fetch("https://convert.toolkitapi.io/v1/convert/data", {
  method: "POST",
  headers: {
    "X-API-Key": process.env.CONVERT_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    from_format: "xml",
    to_format: "json",
    data: "<users><user><name>Alice</name><age>30</age></user></users>",
    strip_namespaces: true,
  }),
});
const { result } = await resp.json();
console.log(JSON.parse(result));

Python SDK Examples

from toolkitapi import Convert

cv = Convert(api_key="tk_...")

# JSON → YAML
result = cv.data(
    from_format="json",
    to_format="yaml",
    data={"name": "Alice", "scores": [95, 87, 92]},
)
print(result["result"])
# name: Alice
# scores:
# - 95
# - 87
# - 92

# JSON array → CSV (nested fields flattened with dot notation)
result = cv.data(
    from_format="json",
    to_format="csv",
    data=[
        {"id": 1, "name": "Alice", "address": {"city": "London"}},
        {"id": 2, "name": "Bob", "address": {"city": "Paris"}},
    ],
)
print(result["result"])
# id,name,address.city
# 1,Alice,London
# 2,Bob,Paris

# CSV → JSON
result = cv.data(
    from_format="csv",
    to_format="json",
    data="name,age\nAlice,30\nBob,25",
    has_header=True,
)
print(result["result"])
# [{"name": "Alice", "age": "30"}, {"name": "Bob", "age": "25"}]

# Download a remote CSV and get it back as YAML bytes
path = cv.data_file(
    url="https://toolkitapi.io/data/products.csv",
    from_format="csv",
    to_format="yaml",
    has_header=True,
    output_path="products.yaml",
)
print(f"Saved to {path}")

Errors

Status Meaning
400 Invalid source, unsupported conversion pair, or format-specific error
401 Missing or invalid API key
413 Source file exceeds the maximum size
422 Validation error (both/neither data and url, unknown format)

See Error Handling for the shared error envelope.