/api/convert/toml-to-json
MCP tool toml_to_json Parses input as TOML 1.0.0 and returns the same data as JSON text and as a JSON value. Tables become objects and keep their order. Integers within ±(2^53 − 1) are numbers; larger ones are decimal strings so no digit is lost. inf, -inf and nan become the strings "inf", "-inf" and "nan". An offset date-time becomes an ISO 8601 string with its offset (1979-05-27T07:32:00.000-08:00); a local date-time, date or time becomes its TOML text (1979-05-27T07:32:00.000, 1979-05-27, 07:32:00.000). Fractional seconds are written to the millisecond. Comments are dropped: JSON has none.
Browser version (runs locally): TOML Format & Validate.
Try it
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
input required | string (≤ 200000 chars) | — | The TOML text, as a string field or a raw text/plain POST body. |
indent | integer (0–8) | 2 | Spaces per JSON indentation level; 0 gives minified JSON. |
Also accepted on every endpoint: format (json | text).
Parameters may come from the query string, a JSON object body, an urlencoded or multipart form,
or (for input) a text/plain body.
Global parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
format | json | text | json | json returns the documented object. text returns only the primary value as text/plain (see "Text output"). |
Response 200 application/json
| Field | Type | Description |
|---|---|---|
json | string | The JSON text. |
value | any | The same data as a JSON value. |
Text output (format=text, text/plain): The JSON text.
Errors
Errors are JSON: {"error": "<message>", "code": "<code>", "param": "<name>"?}.
| Status | Code | When |
|---|---|---|
422 | unprocessable_input | The TOML is invalid (syntax error, duplicate key or table, integer beyond 64 bits); the message gives the line and column. |
400 | invalid_parameter | input is longer than 200,000 characters, or indent is outside 0–8. |
400 | missing_parameter | A required parameter is absent. |
400 | unknown_parameter | A parameter name is not in the table above (typos are rejected, not ignored). |
413 | payload_too_large | The request body exceeds 1 MiB. |
405 | method_not_allowed | A method other than GET, POST or OPTIONS. |
Behaviour
- Idempotent: the same arguments always return the same result.
-
Requires a client ID and secret (authentication). Each call is
recorded as one metadata row against your client ID; inputs and outputs are never stored or
logged. Responses carry
cache-control: no-store. - CORS: any origin may call this endpoint from a browser, using your credentials.
Examples
Responses below were produced by running each request through this code at build time. Long strings are shortened.
Tables, an array of tables and dates
curl -X POST 'https://util.caruana.me/api/convert/toml-to-json' \
-H 'content-type: application/json' \
-d '{"input":"title = \"TOML Example\"\n\n[owner]\nname = \"Tom\"\ndob = 1979-05-27T07:32:00-08:00\n\n[[products]]\nname = \"Hammer\"\nsku = 738594937\n\n[[products]]\nname = \"Nail\"\nsku = 284758393\ncolor = \"gray\"\n"}'
Response 200
{
"json": "{\n \"title\": \"TOML Example\",\n \"owner\": {\n \"name\": \"Tom\",\n \"dob\": \"1979-05-27T07:32:00.000-08:00\"\n },\n \"products… (150 more characters)",
"value": {
"title": "TOML Example",
"owner": {
"name": "Tom",
"dob": "1979-05-27T07:32:00.000-08:00"
},
"products": [
{
"name": "Hammer",
"sku": 738594937
},
{
"name": "Nail",
"sku": 284758393,
"color": "gray"
}
]
}
}
Same call as an MCP tools/call
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "toml_to_json",
"arguments": {
"input": "title = \"TOML Example\"\n\n[owner]\nname = \"Tom\"\ndob = 1979-05-27T07:32:00-08:00\n\n[[products]]\nname = \"Hammer\"\nsku = 738594937\n\n[[products]]\nname = \"Nail\"\nsku = 284758393\ncolor = \"gray\"\n"
}
}
}Special floats and a 64-bit integer, minified
curl -X POST 'https://util.caruana.me/api/convert/toml-to-json' \
-H 'content-type: application/json' \
-d '{"input":"big = 9223372036854775807\nratio = inf\nmissing = nan\nwhen = 07:32:00\n","indent":0}'
Response 200
{
"json": "{\"big\":\"9223372036854775807\",\"ratio\":\"inf\",\"missing\":\"nan\",\"when\":\"07:32:00.000\"}",
"value": {
"big": "9223372036854775807",
"ratio": "inf",
"missing": "nan",
"when": "07:32:00.000"
}
}
Same call as an MCP tools/call
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "toml_to_json",
"arguments": {
"input": "big = 9223372036854775807\nratio = inf\nmissing = nan\nwhen = 07:32:00\n",
"indent": 0
}
}
}