/api/convert/json-to-yaml
MCP tool json_to_yaml Parses input strictly as JSON and writes it as a YAML 1.2 document (block style, no --- marker, no line folding). Key order is kept unless sort_keys is set; integers keep every digit; 1.0 stays 1.0. Strings that a YAML 1.1 parser would read as something else (yes, no, on, off, y, n, 0755, 1:20, 2024-01-01, <<, …) or that YAML 1.2 would read as a number, boolean or null are double-quoted, so the output means the same under both versions. Multi-line strings use literal block scalars (|). Duplicate keys keep the last value, with a warning.
Browser version (runs locally): YAML Format & Validate.
Try it
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
input required | string (≤ 100000 chars) | — | The JSON text, as a string field or a raw text/plain POST body. |
indent | integer (2–8) | 2 | Spaces per YAML indentation level. |
sort_keys | boolean | false | Sort object keys recursively, by UTF-16 code units (the order RFC 8785 uses). Array order never changes. |
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 |
|---|---|---|
yaml | string | The YAML document, ending with a newline. |
warnings | array of object | Valid-but-risky findings: integers beyond 2^53 − 1, numbers that overflow a double, unpaired surrogate escapes, duplicate keys. At most 100 are listed. |
warnings[].message | string | Plain-language finding. |
warnings[].pointer | string | JSON Pointer of the value concerned. |
warnings[].line | integer | 1-based line number. |
warnings[].column | integer | 1-based column, counted in Unicode code points. |
warnings[].offset | integer | 0-based offset in code points. |
Text output (format=text, text/plain): The YAML document.
Errors
Errors are JSON: {"error": "<message>", "code": "<code>", "param": "<name>"?}.
| Status | Code | When |
|---|---|---|
422 | unprocessable_input | input is not valid JSON; the message gives the line, column and offset and how to fix it. |
400 | invalid_parameter | input is longer than 100,000 characters, or indent is outside 2–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.
Values that need quoting for YAML 1.1 readers
curl -X POST 'https://util.caruana.me/api/convert/json-to-yaml' \
-H 'content-type: application/json' \
-d '{"input":"{\"country\":\"no\",\"mode\":\"0755\",\"enabled\":true,\"ratio\":1.0,\"notes\":\"line 1\\nline 2\",\"ports\":[80,443]}"}'
Response 200
{
"yaml": "country: \"no\"\nmode: \"0755\"\nenabled: true\nratio: 1.0\nnotes: |-\n line 1\n line 2\nports:\n - 80\n - 443\n",
"warnings": []
}
Same call as an MCP tools/call
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "json_to_yaml",
"arguments": {
"input": "{\"country\":\"no\",\"mode\":\"0755\",\"enabled\":true,\"ratio\":1.0,\"notes\":\"line 1\\nline 2\",\"ports\":[80,443]}"
}
}
}