JSON to YAML Converter

JSON to YAML Converter API

Development

Convert JSON to YAML and YAML to JSON as you type, with indentation and key-sorting options, errors that point to the line and column, and copy or download.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Convert JSON to YAML or YAML to JSON. Send the text and the direction, and get the converted text back along with any warnings.

Behavior

  • json-to-yaml: the JSON must be strictly valid (no comments, trailing commas or single quotes). Lines are not wrapped. Integers larger than 9,007,199,254,740,991 are rounded and a warning says so; quote them as strings to keep every digit.
  • yaml-to-json: a file with several documents (separated by ---) becomes a JSON array with one item per document, and a warning says so. The values .inf and .nan become null with a warning. Alias expansion is capped at 100.
  • sortKeys sorts object keys alphabetically at every level. Arrays keep their order.

Errors

Invalid input returns a 400. The error message describes the first problem, and details holds its line and column (both 1-based) when they are known.

Notes

  • text is limited to 500,000 characters.
  • jsonIndent applies to YAML to JSON output and yamlIndent to JSON to YAML output.

Endpoints

POST
https://opentools.ca/api/v1/tools/json-yaml-converter
Convert JSON to YAML or YAML to JSON

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
direction
string
Enum: json-to-yaml, yaml-to-json
Required
Which way to convert
text
string
Required
The JSON or YAML to convert, 1-500,000 characters
jsonIndent
number or string
OptionalIndentation of JSON output: 2, 4, 0 (minified) or "tab"Default: 2
yamlIndent
number
OptionalIndentation of YAML output: 2 or 4Default: 2
sortKeys
boolean
OptionalSort object keys alphabeticallyDefault: false

Response Example

{
  "success": true,
  "direction": "json-to-yaml",
  "output": "name: app\nports:\n  - 80\n  - 443\ndebug: false\n",
  "warnings": []
}

Error Codes

400
Bad Request - Invalid options, or JSON or YAML that does not parse (details has the line and column)
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key is inactive or expired, or the request IP is not allowed
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

curl -X POST https://opentools.ca/api/v1/tools/json-yaml-converter \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "direction": "json-to-yaml",
    "text": "{\"name\":\"app\",\"ports\":[80,443],\"debug\":false}"
  }'

Ready to get started?

Create an API key to start using the JSON to YAML Converter API.

Rather use it in your browser? Open the JSON to YAML Converter