How to convert data formats in code
Convert structured data between JSON, CSV, TSV, YAML, and XML from any language by POSTing to a single endpoint. Examples below.
curl
curl -X POST "https://data.wrapper-agency.com/api/v1/convert" \
-H "Content-Type: application/json" \
-d '{"from":"json","to":"yaml","data":"{\"hello\":\"world\"}"}'JavaScript (fetch)
const res = await fetch("https://data.wrapper-agency.com/api/v1/convert", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
from: "csv",
to: "json",
data: "id,name\n1,Ada\n2,Alan",
}),
});
const { output } = await res.json();
console.log(output);Python (requests)
import requests
r = requests.post(
"https://data.wrapper-agency.com/api/v1/convert",
json={
"from": "yaml",
"to": "json",
"data": "name: Ada\nrole: Engineer",
},
)
print(r.json()["output"])Notes
- Tabular ↔ structured. When converting CSV/TSV to JSON/YAML/XML, the header row becomes object keys and each data row becomes a record. Going the other way, an array of objects becomes rows.
- Type coercion. CSV/TSV cells that look like numbers,
true/false, ornullare coerced when converting into JSON/YAML/XML. - XML root. Output XML is wrapped in a
<root>element; arrays use repeated<item>elements.
See the full API reference, or try a conversion on any of the format pages.