API reference

Convert JSON to YAML

Convert JSON to YAML 1.2, quoting strings that YAML 1.1 parsers would misread.

GETPOST/api/convert/json-to-yamlMCP 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

Credentials
Remember these credentials

Not saved: you will paste them again next time.

No credentials yet? Get a client ID and secret. They are sent only to this site, in an Authorization: Basic header.

POST /api/convert/json-to-yaml with a JSON body

Parameters

ParameterTypeDefaultDescription
inputrequiredstring (≤ 100000 chars)—The JSON text, as a string field or a raw text/plain POST body.
indentinteger (2–8)2Spaces per YAML indentation level.
sort_keysbooleanfalseSort 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
ParameterTypeDefaultDescription
formatjson | textjsonjson returns the documented object. text returns only the primary value as text/plain (see "Text output").

Response 200 application/json

FieldTypeDescription
yamlstringThe YAML document, ending with a newline.
warningsarray of objectValid-but-risky findings: integers beyond 2^53 − 1, numbers that overflow a double, unpaired surrogate escapes, duplicate keys. At most 100 are listed.
warnings[].messagestringPlain-language finding.
warnings[].pointerstringJSON Pointer of the value concerned.
warnings[].lineinteger1-based line number.
warnings[].columninteger1-based column, counted in Unicode code points.
warnings[].offsetinteger0-based offset in code points.

Text output (format=text, text/plain): The YAML document.

Errors

Errors are JSON: {"error": "<message>", "code": "<code>", "param": "<name>"?}.

StatusCodeWhen
422unprocessable_inputinput is not valid JSON; the message gives the line, column and offset and how to fix it.
400invalid_parameterinput is longer than 100,000 characters, or indent is outside 2–8.
400missing_parameterA required parameter is absent.
400unknown_parameterA parameter name is not in the table above (typos are rejected, not ignored).
413payload_too_largeThe request body exceeds 1 MiB.
405method_not_allowedA 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]}"
    }
  }
}