What does the YAML Diff do?
The YAML Diff & Compare Tool on blueutils.com performs deep semantic comparisons between two YAML documents. It parses both inputs into abstract syntax trees and highlights added, removed, modified, and unchanged properties with dot-notation path references, ignoring non-semantic differences such as key ordering or cosmetic whitespace.
Core Concepts
Understanding semantic AST-level comparison prevents misleading diff results:
- Semantic Comparison vs. Line Diff: Line-based diff tools flag re-ordered keys or altered indentation widths as changes. The semantic diff compares parsed object models directly, ignoring key order.
- Hierarchical Path Resolution: Pinpoints exact modifications using hierarchical dot-notation paths (e.g.
services.web.environment.DATABASE_URL). - Granular Change Classification: Classifies every leaf and collection node as
added,removed,modified, orunchanged.
How to use the tool?
- Paste or Upload YAML Payloads: Paste your baseline (original) YAML into the Original YAML (Baseline) pane on the left and your updated (modified) YAML into the Modified YAML (Target) pane on the right, upload
.yamlfiles, or click Sample. - Real-Time Comparison: The comparison executes automatically in real time as you type or paste without requiring manual submit actions.
- Inspect & Export Output: Review the structured differences list showing property paths, previous values, and target values, then click Copy Diff to copy the summary report.
Related Developer Utilities
If you work with YAML configurations, Kubernetes manifests, and text comparison tools, explore these related utilities:
- JSON Diff Tool: Compare two JSON objects side-by-side with structural diff detection.
- Text Diff Tool: Compare two plain text documents with character-level inline diffing.
- YAML Syntax Validator: Validate YAML syntax and find line/column errors.
- YAML Formatter & Beautifier: Clean and re-indent messy YAML documents.
- YAML Minifier & Compressor: Minify YAML manifests into compact flow style.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/diff) to programmatically compare two YAML documents and output deep structural differences.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
leftRaw / original |
String / Object | Original (baseline) raw YAML document string or parsed object. | "version: \"3.8\"\nservices:\n web:\n image: node:18" |
rightRaw / modified |
String / Object | Modified (target) raw YAML document string or parsed object. | "version: \"3.8\"\nservices:\n web:\n image: node:20" |
API Request Payload Examples
cURL (Using Raw String)
curl -X POST https://blueutils.com/api/yaml/diff \
-H "Content-Type: application/json" \
-d '{
"leftRaw": "version: \"3.8\"\nservices:\n web:\n image: node:18-alpine",
"rightRaw": "version: \"3.8\"\nservices:\n web:\n image: node:20-alpine\n ports:\n - \"3000:3000\""
}'cURL (Using Direct Objects)
curl -X POST https://blueutils.com/api/yaml/diff \
-H "Content-Type: application/json" \
-d '{
"original": {
"version": "3.8",
"services": { "web": { "image": "node:18-alpine" } }
},
"modified": {
"version": "3.8",
"services": { "web": { "image": "node:20-alpine" } }
}
}'Python
import requests
url = "https://blueutils.com/api/yaml/diff"
payload = {
"leftRaw": "version: \"3.8\"\nservices:\n web:\n image: node:18-alpine",
"rightRaw": "version: \"3.8\"\nservices:\n web:\n image: node:20-alpine\n ports:\n - \"3000:3000\""
}
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 = """
{
"leftRaw": "version: \\"3.8\\"\\nservices:\\n web:\\n image: node:18-alpine",
"rightRaw": "version: \\"3.8\\"\\nservices:\\n web:\\n image: node:20-alpine"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/yaml/diff"))
.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 both YAML documents were compared successfully. | true |
message |
String | Summary message returned on completion. | "YAML differences found." |
isIdentical |
Boolean | Indicates whether both documents are structurally identical. | false |
result |
Object | High-level comparison result object containing isIdentical, summary, and diffs. |
{...} |
data |
Object | Parsed baseline and modified objects (original and modified). |
{"original":{...},"modified":{...}} |
summary |
Object | Summary counts of added, removed, modified, unchanged, and totalChanges. |
{"added":1,"modified":1} |
diffs |
Array | Detailed array of difference items with type, path, leftValue, and rightValue. |
[...] |
originalSize |
Number | Byte size of baseline input. | 64 |
resultSize |
Number | Byte size of modified target input. | 82 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"message": "YAML differences found.",
"isIdentical": false,
"result": {
"isIdentical": false,
"summary": {
"added": 1,
"removed": 0,
"modified": 1,
"unchanged": 1,
"totalChanges": 2
},
"diffs": [
{
"type": "modified",
"path": "services.web.image",
"leftValue": "node:18-alpine",
"rightValue": "node:20-alpine"
},
{
"type": "added",
"path": "services.web.ports",
"leftValue": null,
"rightValue": [
"3000:3000"
]
}
]
},
"data": {
"original": {
"version": "3.8",
"services": {
"web": {
"image": "node:18-alpine"
}
}
},
"modified": {
"version": "3.8",
"services": {
"web": {
"image": "node:20-alpine",
"ports": [
"3000:3000"
]
}
}
}
},
"summary": {
"added": 1,
"removed": 0,
"modified": 1,
"unchanged": 1,
"totalChanges": 2
},
"diffs": [
{
"type": "modified",
"path": "services.web.image",
"leftValue": "node:18-alpine",
"rightValue": "node:20-alpine"
},
{
"type": "added",
"path": "services.web.ports",
"leftValue": null,
"rightValue": [
"3000:3000"
]
}
],
"originalSize": 64,
"resultSize": 82
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Original YAML syntax error (Line 1, Column 12): Unexpected scalar token",
"details": {
"line": 1,
"col": 12,
"side": "original"
}
}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 diff YAML documents?
Integrating the YAML Diff API into automated CI/CD deployment gates, GitOps change detectors, or cloud configuration auditing tools provides practical benefits:
- Rapid Script Validation: Enables deployment bots to verify exact configuration changes between staging and production manifests before applying updates.
- Optimized Token Efficiency for AI Agents: LLMs struggle with multi-page line diff analysis. The API returns a structured difference AST, saving hundreds of context tokens.
- Deterministic Accuracy Without Hallucinations: Ensures 100% accurate key-level difference tracking without misidentifying unchanged fields or hallucinating modified properties.
Native Usage
How to compare YAML files locally using code editors, terminal CLI utilities, and programming runtimes without external web services:
Visual Studio Code & JetBrains Shortcuts
- VS Code: Select two YAML files in the File Explorer, right-click, and select Compare Selected. Or open command palette (
Ctrl+Shift+P/Cmd+Shift+P) and typeFile: Compare Active File With.... - JetBrains IDEs: Select two files, right-click, and select Compare Files (
Ctrl+D/Cmd+D).
Windows (CMD / PowerShell)
# Compare YAML using Python in PowerShell
python -c "
import yaml
d1 = yaml.safe_load(open('f1.yaml'))
d2 = yaml.safe_load(open('f2.yaml'))
print('Identical' if d1 == d2 else 'Differences detected')
"Linux / Unix (Bash)
# Using dyff CLI for semantic YAML diffing
dyff between file1.yaml file2.yaml
# Or using yq with standard diff
diff -u <(yq -P 'sort_keys(..)' file1.yaml) <(yq -P 'sort_keys(..)' file2.yaml)Python
Using deepdiff or standard library dictionary comparison:
import yaml
from deepdiff import DeepDiff
with open('file1.yaml', 'r', encoding='utf-8') as f1, open('file2.yaml', 'r', encoding='utf-8') as f2:
doc1 = yaml.safe_load(f1)
doc2 = yaml.safe_load(f2)
diff = DeepDiff(doc1, doc2, ignore_order=True)
print("YAML Differences:", diff)Java
Using Jackson (JsonNode) and zjsonpatch in Java 17+:
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.flipkart.zjsonpatch.JsonDiff;
import java.io.File;
public class YamlDiffExample {
public static void main(String[] args) throws Exception {
YAMLMapper mapper = new YAMLMapper();
JsonNode tree1 = mapper.readTree(new File("file1.yaml"));
JsonNode tree2 = mapper.readTree(new File("file2.yaml"));
JsonNode patch = JsonDiff.asJson(tree1, tree2);
System.out.println("Diff patch: " + patch.toPrettyString());
}
}