Data Formats

2 endpoints for converting structured data between JSON, CSV, XML, YAML, and TOML — in any direction.

Method Endpoint Purpose
POST /v1/convert/data Convert between JSON, CSV, XML, YAML, and TOML
GET /v1/convert/data Stream a converted file from a URL source

Python SDK Examples

JSON to YAML

from toolkitapi import Convert

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

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 to CSV

from_format="json" with a list of objects flattens nested fields using dot notation (e.g. address.city).

from toolkitapi import Convert

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

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 to JSON

from toolkitapi import Convert

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

csv_text = "name,age\nAlice,30\nBob,25"

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

XML to JSON

from toolkitapi import Convert

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

xml_text = "<users><user><name>Alice</name><age>30</age></user></users>"

result = cv.data(
    from_format="xml",
    to_format="json",
    data=xml_text,
    strip_namespaces=True,
)
import json
print(json.dumps(json.loads(result["result"]), indent=2))

Convert from a remote URL and download the file

The _file variant fetches the source from a URL and streams the converted bytes back directly.

from toolkitapi import Convert

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

# 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}")

TOML to JSON

from toolkitapi import Convert

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

toml_text = '[server]\nhost = "localhost"\nport = 8080'

result = cv.data(
    from_format="toml",
    to_format="json",
    data=toml_text,
)
print(result["result"])
# {"server": {"host": "localhost", "port": 8080}}

Request Parameters

Parameter 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 — JSON value or 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)

Response Fields

Field Type Description
result string The converted content as a string
from_format string Source format used
to_format string Target format used
metadata object Stats such as rows, columns, word_count, etc.

Tip

Provide url instead of data to fetch and convert a remote file in a single call. Use data_file() (the GET variant) to receive the converted content as a direct file download rather than a JSON wrapper.