What does the YAML Schema Validator do?
The YAML Schema Validator on blueutils.com checks YAML data structures and configuration files against JSON Schema specifications (Draft-07 / Draft-04). Powered by AJV, it validates data types, required attributes, regular expression string patterns, enumerations, numeric ranges, and array limits, providing JSON pointer error locations for non-compliant properties.
Core Concepts
Understanding YAML schema validation rules helps verify configuration integrity:
- Schema Format Interoperability: Schemas can be authored in clean YAML syntax or traditional JSON formatting. The validator automatically parses both formats into memory before schema compilation.
- AJV Fast Validation Engine: Enforces strict JSON Schema standards (including Draft-07 keyword rules:
type,properties,required,additionalProperties,minimum,maximum, andpattern). - Instance Path Pointer Diagnostics: Pinpoints structural failures with standard RFC 6901 JSON pointers (e.g.
/servers/0/portor/database/connectionTimeout).
How to use the tool?
- Provide Schema Definition: Paste your JSON Schema (in YAML or JSON format) into the left YAML / JSON Schema Definition editor, click Upload Schema, or click Sample Schema.
- Provide Target YAML Data: Paste the YAML document you want to test against the contract into the right Target YAML Data Payload editor, click Upload Data, or click Sample Data.
- Live Verification: The validator checks your target data against the schema automatically in real time as you edit or upload.
Related Developer Utilities
If you work with schema validation, API contracts, and YAML configurations, explore these related tools:
- JSON Schema Validator: Validate JSON documents and API responses against Draft-07 / 2020-12 schemas.
- Kubernetes Manifest Validator: Validate Kubernetes resource manifests against official schemas.
- YAML Syntax Validator: Validate YAML indentation rules and detect syntax errors.
- YAML to TypeScript Converter: Generate strongly-typed TypeScript interfaces from YAML structures.
- YAML Formatter & Beautifier: Clean and re-indent messy YAML configuration files.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/schema) to programmatically validate YAML configuration payloads against JSON or YAML schemas.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
data / yaml |
String / Object | Raw target YAML document string or parsed object to validate. | "service: web-api\nreplicas: 3" |
schema / rules |
String / Object | The YAML or JSON Schema rules string or parsed object to validate against. | "type: object\nproperties:\n service:\n type: string" |
API Request Payload Examples
cURL (Using Raw String)
curl -X POST https://blueutils.com/api/yaml/schema \
-H "Content-Type: application/json" \
-d '{
"data": "service: web-api\nreplicas: 3",
"schema": "type: object\nproperties:\n service:\n type: string\n replicas:\n type: integer\nrequired:\n - service\n - replicas"
}'cURL (Using Direct Objects)
curl -X POST https://blueutils.com/api/yaml/schema \
-H "Content-Type: application/json" \
-d '{
"yaml": {
"service": "web-api",
"replicas": 3
},
"rules": {
"type": "object",
"properties": {
"service": { "type": "string" },
"replicas": { "type": "integer" }
},
"required": ["service", "replicas"]
}
}'Python
import requests
url = "https://blueutils.com/api/yaml/schema"
payload = {
"data": "service: web-api\nreplicas: 3",
"schema": "type: object\nproperties:\n service:\n type: string\n replicas:\n type: integer\nrequired:\n - service\n - replicas"
}
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 = """
{
"data": "service: web-api\\nreplicas: 3",
"schema": "type: object\\nproperties:\\n service:\\n type: string\\n replicas:\\n type: integer\\nrequired:\\n - service\\n - replicas"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/yaml/schema"))
.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 | Returns true if the YAML payload satisfies the target schema. |
true |
message |
String | Confirmation message returned when validation succeeds. | "YAML data matches the provided schema successfully." |
data |
Object / Array | Parsed native representation of the validated YAML document. | {"service":"web-api"} |
schema |
Object | Parsed native representation of the target schema. | {"type":"object"} |
originalSize |
Number | Byte size of the raw target data input in UTF-8. | 30 |
resultSize |
Number | Byte size of the target schema definition in UTF-8. | 98 |
errors |
Array | Array of specific error objects (path, message, params) when validation fails. |
[...] |
error |
String | Summary error message returned when validation fails. | "YAML schema validation failed." |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"message": "YAML data matches the provided schema successfully.",
"data": {
"service": "web-api",
"replicas": 3
},
"schema": {
"type": "object",
"properties": {
"service": { "type": "string" },
"replicas": { "type": "integer" }
},
"required": ["service", "replicas"]
},
"originalSize": 30,
"resultSize": 98
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "YAML schema validation failed.",
"errors": [
{
"path": "/replicas",
"message": "must be integer",
"params": { "type": "integer" }
}
]
}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 validate YAML against a schema?
Integrating the YAML Schema Validator API into deployment pipelines, Git hooks, or testing tools provides several key advantages:
- Rapid Script Validation: Enables automated CI/CD checks to verify microservice configuration files, OpenAPI specs, and deployment manifests against strict schemas before rollout.
- Optimized Token Efficiency for AI Agents: Offloading schema checking to an API prevents AI agents from spending LLM generation tokens on tedious constraint matching.
- Deterministic Accuracy Without Hallucinations: Ensures 100% deterministic schema enforcement using AJV without missed required keys or hallucinated type assertions.
Native Usage
How to validate YAML files against JSON schemas locally using terminal tools and scripts:
Visual Studio Code & JetBrains Shortcuts
- VS Code: Use
$schemamodeline oryaml.schemassetting in.vscode/settings.json. - JetBrains IDEs: Configure JSON Schema mappings under Settings > Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings.
Windows (CMD / PowerShell)
# Validate YAML against schema using check-jsonschema CLI
check-jsonschema --schemafile schema.json config.yamlLinux / Unix (Bash)
# Validate YAML configuration against schema in terminal
check-jsonschema --schemafile schema.json config.yamlPython
Using jsonschema and PyYAML in Python:
import yaml
import jsonschema
with open("schema.yaml", "r", encoding="utf-8") as sf, open("data.yaml", "r", encoding="utf-8") as df:
schema = yaml.safe_load(sf)
data = yaml.safe_load(df)
try:
jsonschema.validate(instance=data, schema=schema)
print("YAML data satisfies schema!")
except jsonschema.exceptions.ValidationError as e:
print(f"Validation error at {e.json_path}: {e.message}")Java
Using NetworkNT json-schema-validator and Jackson in Java 17+:
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;
import java.io.File;
import java.util.Set;
public class YamlSchemaValidatorExample {
public static void main(String[] args) throws Exception {
YAMLMapper mapper = new YAMLMapper();
JsonNode dataNode = mapper.readTree(new File("data.yaml"));
JsonNode schemaNode = mapper.readTree(new File("schema.yaml"));
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
JsonSchema schema = factory.getSchema(schemaNode);
Set<ValidationMessage> errors = schema.validate(dataNode);
if (errors.isEmpty()) {
System.out.println("YAML payload satisfies the schema.");
} else {
errors.forEach(err -> System.err.println(err.getMessage()));
}
}
}