Made on Earth Donate

JSON / CSV / PHP converter API

Converts between JSON, XML, CSV, query strings, YAML and PHP array code, var_dump(), print_r() and serialize(), in any direction.

Converts data between nine formats in any direction, the same way as the converter page. PHP input is parsed, never run: array code takes literals only, and serialize() output is read without unserialize(), repairing the wrong string lengths a database search-and-replace leaves behind.

Endpoint

POST https://supertoolshq.com/api/v1/developer/data-converter/   (form-encoded body)
GET  https://supertoolshq.com/api/v1/developer/data-converter/

Parameters

NameValuesDefaultMeaning
textTextrequiredThe data to convert, up to 2 MB. Send it as a POST body: most of it won’t fit in a URL.
fromFormatautoWhat text is (see formats). auto or empty detects it.
toFormatjsonWhat to turn it into.
assoc1 or 01For the PHP outputs: objects become associative arrays, like json_decode($json, true). With 0 they stay stdClass objects. JSON and XML output always keep objects as objects.

Formats

ValueFormat
jsonJSON
xmlXML
csvCSV
queryQuery string
yamlYAML
phpPHP array
var_dumpvar_dump()
print_rprint_r()
serializeSerialize

print_r() and CSV carry no types, so numbers become numbers and everything else stays text. CSV takes its column names from the first row and detects the delimiter (comma, semicolon, tab or pipe). Query strings may be a whole URL. XML attributes appear under @attributes. YAML follows YAML 1.2 (yes and no stay text), keeps numbers with a leading zero such as 0644 as text, and turns several --- documents into a list.

Response

FieldTypeMeaning
fromobjectThe input’s format, its label, and detected: whether it was detected rather than given.
toobjectThe output’s format and label.
outputstringThe converted text.

Example

curl -X POST https://supertoolshq.com/api/v1/developer/data-converter/ --data-urlencode 'text={"name": "Ada", "langs": ["PHP", "SQL"], "admin": true}' -d to=php
{
    "from": {
        "format": "json",
        "label": "JSON",
        "detected": true
    },
    "to": {
        "format": "php",
        "label": "PHP array"
    },
    "output": "[\n    'name' => 'Ada',\n    'langs' => [\n        'PHP',\n        'SQL',\n    ],\n    'admin' => true,\n]"
}

Detected input

Without from, the format is detected; here a var_dump() from a log, converted to the default, JSON:

{
    "from": {
        "format": "var_dump",
        "label": "var_dump()",
        "detected": true
    },
    "to": {
        "format": "json",
        "label": "JSON"
    },
    "output": "{\n    \"id\": 7,\n    \"tags\": [\n        \"new\"\n    ]\n}"
}

Errors

Bad parameters get HTTP 400 with a message per field:

{
    "errors": {
        "to": "One of json, xml, csv, query, yaml, php, var_dump, print_r, serialize."
    }
}

Text that doesn’t parse as its format is HTTP 400 too, with the reason under text and the format it was read as:

{
    "errors": {
        "text": "This isn't valid JSON: syntax error."
    },
    "from": {
        "format": "json",
        "label": "JSON",
        "detected": false
    }
}

From code

// JavaScript
const res = await fetch('https://supertoolshq.com/api/v1/developer/data-converter/', { method: 'POST', body: new URLSearchParams({ text: 'a=1&b[]=2', to: 'json' }) });
const data = await res.json();
console.log(data.from.format, data.output);
# Python
import json, urllib.parse, urllib.request
body = urllib.parse.urlencode({'text': open('option.txt').read(), 'from': 'serialize', 'to': 'json'}).encode()
print(json.load(urllib.request.urlopen('https://supertoolshq.com/api/v1/developer/data-converter/', body))['output'])

The conventions every API here follows (methods, errors, versions) are in the API overview.