YAML ⇄ JSON API

Convert YAML to JSON or JSON to YAML in one endpoint, with multi-document support and syntax errors reported with line and column.

POSThttps://apibox.io.vn/v1/yaml

Send yaml to get JSON, or json to get YAML; the direction is picked automatically and can be forced with to=json or to=yaml. YAML can also be posted as a raw text body (for example text/yaml) with to=json.

YAML to JSON returns valid, the parsed value in json and the number of documents; files with several documents separated by --- return an array. Invalid YAML returns valid: false with an error message, line and column instead of an HTTP error.

JSON to YAML accepts a JSON value or JSON string in json and returns the YAML text in yaml; indent sets the indentation (1 to 8, default 2). The request body is limited to 5 MB.

Parameters

NameInTypeRequiredDefault
yamlbodystringnoYAML text to convert to JSON. Can also be sent as a raw text body with to=json.
jsonbodyobjectnoJSON value or JSON string to convert to YAML.
tobody|querystringnoTarget format: json or yaml. Default: json when yaml is sent, otherwise yaml.
indentbody|querynumberno2YAML indentation (1-8) when converting to YAML.

Example

curl -X POST "https://apibox.io.vn/v1/yaml" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"yaml":"name: APIBox\nversion: 1\nfeatures:\n  - html\n  - json\nenabled: true"}'

Response

{
  "valid": true,
  "json": {
    "name": "APIBox",
    "version": 1,
    "features": [
      "html",
      "json"
    ],
    "enabled": true
  },
  "documents": 1
}

Use cases

  • Convert Kubernetes, Docker Compose or GitHub Actions YAML to JSON
  • Generate YAML config files from JSON data
  • Validate YAML syntax in CI with exact error positions
  • Read OpenAPI specs written in YAML from JavaScript

FAQ

How do I choose the conversion direction?

Send yaml to get JSON, or json to get YAML. To be explicit, add to=json or to=yaml.

Are multi-document YAML files supported?

Yes. Documents separated by --- are returned as an array in json, and documents gives their count.

How are YAML syntax errors reported?

The response is valid: false with error.message, error.line and error.column.

Related APIs

Start with 1,000 free requests every month. Get free API key →