What does the YAML to JSON Converter do?
The YAML to JSON Converter on blueutils.com transforms human-friendly YAML documents into strict, standard-compliant RFC 8259 JavaScript Object Notation (JSON) payloads. It maps YAML mappings, nested sequences, scalar values, booleans, and nulls into structured JSON objects with customizable indentation formatting (2 spaces, 4 spaces, tab indentation, or minified).
Core Concepts
Understanding data format mapping between YAML and JSON ensures predictable conversion:
- Block & Flow Mappings: YAML key-value pairs (
key: value) and inline flow objects ({key: value}) are mapped into standard JSON key-value objects ({"key": "value"}). - Sequence Arrays: YAML hyphens (
- item) and inline lists ([1, 2, 3]) are converted to standard JSON bracketed arrays ([1, 2, 3]). - Primitive Normalization: Accurately maps unquoted strings, integers, floating-point numbers, boolean values (
true/false), and null representations (null,~).
How to use the tool?
- Paste or Upload YAML: Paste your YAML configuration into the Raw YAML Input editor, upload a
.yamlfile, or click Sample. - Configure Style & Indentation: Select your desired format style (Standard or Minified) and indentation spacing (2 spaces, 4 spaces, Tab, or Custom).
- Review & Export: The converted JSON renders instantly in the Converted JSON Result pane in real time. Click Copy or Download to save your
output.jsonfile.
Related Developer Utilities
If you work with YAML manifests, JSON APIs, and DevOps configuration files, explore these related tools:
- JSON to YAML Converter: Convert JSON documents into clean, human-readable YAML configurations.
- YAML Formatter & Beautifier: Re-indent and format messy YAML documents.
- YAML Syntax Validator: Validate YAML syntax and inspect line/column error positions.
- YAML Minifier & Compressor: Compress YAML documents into ultra-compact flow style.
- YAML Diff Comparator: Compare two YAML documents side-by-side to inspect structural differences.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/to-json) to programmatically convert raw YAML document strings into structured, formatted JSON strings.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText / yaml |
String / Object | Raw YAML document string or parsed object to convert to JSON. | "service: blueutils\nversion: 1" |
indent |
Number / String | JSON indentation spacing (2, 4, 0, or "tab"). Defaults to 2. |
2 |
API Request Payload Examples
cURL (Using Raw String)
curl -X POST https://blueutils.com/api/yaml/to-json \
-H "Content-Type: application/json" \
-d '{
"rawText": "service: blueutils\nversion: 1\nactive: true",
"indent": 2
}'cURL (Using Direct Object)
curl -X POST https://blueutils.com/api/yaml/to-json \
-H "Content-Type: application/json" \
-d '{
"yaml": {
"service": "blueutils",
"version": 1,
"active": true
},
"indent": 2
}'Python
import requests
url = "https://blueutils.com/api/yaml/to-json"
payload = {
"rawText": "service: blueutils\nversion: 1\nactive: true",
"indent": 2
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "service: blueutils\\nversion: 1\\nactive: true",
"indent": 2
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/yaml/to-json"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the input YAML parsed and converted successfully. | true |
message |
String | Success confirmation message. | "YAML converted to JSON successfully." |
result |
String | Converted and formatted JSON payload string. | "{\n \"service\": \"blueutils\"\n}" |
data |
Object / Array | Parsed native object/array representation returned when conversion succeeds. | {"service":"blueutils"} |
originalSize |
Number | Byte size of raw input payload in UTF-8. | 45 |
resultSize |
Number | Byte size of converted JSON output in UTF-8. | 62 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"message": "YAML converted to JSON successfully.",
"result": "{\n \"service\": \"blueutils\",\n \"version\": 1,\n \"active\": true\n}",
"data": {
"service": "blueutils",
"version": 1,
"active": true
},
"originalSize": 45,
"resultSize": 62
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "YAML syntax error (Line 2, Column 5): Unexpected token",
"details": {
"line": 2,
"col": 5
}
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to convert YAML to JSON?
Integrating the YAML to JSON API into CI/CD build scripts, automated deployment tooling, or serverless functions provides key advantages:
- Rapid Script Validation: Enables automated backend pipelines to ingest YAML files from GitHub repositories and translate them directly into JSON API payloads.
- Optimized Token Efficiency for AI Agents: Eliminates the need for LLMs to generate verbose JSON string outputs from YAML inputs, reducing prompt and completion token overhead.
- Deterministic Accuracy Without Hallucinations: Ensures strict RFC 8259 JSON compliance with exact type casting and zero corrupted property keys.
Native Usage
How to convert YAML to JSON locally using code editors, terminal CLI utilities, and programming runtimes without external web services:
Visual Studio Code & JetBrains Shortcuts
- VS Code: Install YAML extensions or run command palette (
Ctrl+Shift+P/Cmd+Shift+P) to convert active YAML files to JSON. - JetBrains IDEs: Right-click file in editor > Refactor > Convert to JSON.
Windows (CMD / PowerShell)
# Convert YAML to JSON using Python in PowerShell
python -c "import yaml, json, sys; print(json.dumps(yaml.safe_load(open('config.yaml')), indent=2))" > output.jsonLinux / Unix (Bash & yq)
# Using yq CLI to convert YAML to JSON
yq -o=json eval '.' config.yaml > output.json
# Convert directly from standard input pipeline
cat manifest.yaml | yq -o=json eval '.' - > output.jsonPython
Using PyYAML and standard json module:
import yaml
import json
with open('config.yaml', 'r', encoding='utf-8') as f:
data = yaml.safe_load(f)
json_str = json.dumps(data, indent=2)
print(json_str)Java
Using Jackson (YAMLMapper and ObjectMapper) in Java 17+:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.File;
public class YamlToJsonExample {
public static void main(String[] args) throws Exception {
YAMLMapper yamlMapper = new YAMLMapper();
Object obj = yamlMapper.readValue(new File("config.yaml"), Object.class);
ObjectMapper jsonMapper = new ObjectMapper();
String json = jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
System.out.println(json);
}
}