What does the YAML to TypeScript Converter do?
The YAML to TypeScript Converter parses structured YAML documents, Kubernetes specs, or OpenAPI manifests and automatically generates strongly-typed TypeScript interface or type definitions. It recursively analyzes scalar types, nested object maps, and sequence arrays to generate clean, modular TypeScript declarations.
Core Concepts
Understanding type inference between YAML and TypeScript:
- Recursive Sub-Interface Generation: Deeply nested object properties are recursively decoupled into dedicated, modular sub-interface structures with pascal-cased type names.
- Interfaces vs. Type Aliases: Supports generating either open
interface RootObject { ... }declarations or immutabletype RootObject = { ... }aliases. - Primitive Normalization: Accurately infers TypeScript primitives (
string,number,boolean,any[],null) from YAML scalar values.
How to use the tool?
- Input YAML Document: Paste or upload your YAML configuration, manifest, or data payload into the editor or click Sample.
- Configure TypeScript Options:
- Set the Root Type Identifier (e.g.
AppConfig,UserSchema). - Select between Interfaces or Type Aliases in the top toolbar.
- Set the Root Type Identifier (e.g.
- Copy & Export: Definitions generate instantly in real time. Click Copy or Download to save your
.tsfile.
Related Developer Utilities
If you work with TypeScript interfaces, YAML configs, and type generation, explore these related tools:
- JSON to TypeScript Converter: Generate TypeScript interfaces from JSON datasets.
- YAML to JSON Converter: Convert YAML manifests into standard JSON payloads.
- YAML Formatter: Clean and format indentation for large YAML documents.
- YAML Syntax Validator: Validate YAML syntax and inspect character offsets.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/to-typescript) to programmatically convert YAML configuration documents or API payloads into strongly-typed TypeScript interfaces or type aliases.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawYaml |
String | Input YAML document payload string (aliases: rawText, yaml, data, payload, input). |
"appName: Blueutils\nport: 8080" |
rootName |
String | Name of the generated root interface (aliases: name, root). Defaults to "RootObject". |
"AppConfig" |
useTypeAlias |
Boolean | Generate type aliases instead of interface (aliases: typeAlias, typeMode). Defaults to false. |
false |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/yaml/to-typescript \
-H "Content-Type: application/json" \
-d '{
"rawYaml": "appName: Blueutils\nserver:\n port: 8080",
"rootName": "AppConfig",
"useTypeAlias": false
}'Python
import requests
url = "https://blueutils.com/api/yaml/to-typescript"
payload = {
"rawYaml": "appName: Blueutils\nserver:\n port: 8080",
"rootName": "AppConfig",
"useTypeAlias": False
}
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 = """
{
"rawYaml": "appName: Blueutils\\nserver:\\n port: 8080",
"rootName": "AppConfig",
"useTypeAlias": false
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/yaml/to-typescript"))
.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 operation succeeded. | true |
result |
String | Formatted TypeScript interface or type alias definitions. | "export interface AppConfig {\n appName: string;\n}" |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "export interface Server {\n port: number;\n}\n\nexport interface AppConfig {\n appName: string;\n server: Server;\n}"
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "YAML payload input cannot be empty."
}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 TypeScript?
Integrating the YAML to TypeScript API into automated build systems, code generators, or CLI scaffolding tools provides essential benefits:
- Rapid Script Validation: Automatically generates typed model files from YAML API contracts and Kubernetes CRDs before running frontend build steps.
- Optimized Token Efficiency for AI Agents: LLMs often generate inaccurate TypeScript generic types from complex YAML. Calling the API produces 100% accurate, compiler-ready TypeScript types without burning tokens.
- Deterministic Accuracy Without Hallucinations: Ensures strict type inference across deep object trees, nested arrays, and optional properties.
Native Usage
How to generate TypeScript interfaces from YAML locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Using yq and json-to-ts in PowerShell
yq -o=json config.yaml | npx json-to-tsLinux / Unix (Bash)
# Using yq and quicktype CLI
yq -o=json config.yaml | npx quicktype --lang typescript --top-level AppConfigPython
Using PyYAML to generate basic TypeScript interfaces:
import yaml
def yaml_to_ts(yaml_file, root_name="AppConfig"):
with open(yaml_file) as f:
data = yaml.safe_load(f)
def infer_type(v):
if isinstance(v, bool): return "boolean"
if isinstance(v, (int, float)): return "number"
if isinstance(v, str): return "string"
if isinstance(v, list): return f"{infer_type(v[0])}[]" if v else "any[]"
if isinstance(v, dict): return "{\n" + "\n".join([f" {k}: {infer_type(val)};" for k, val in v.items()]) + "\n}"
return "any"
return f"export interface {root_name} {infer_type(data)}"
print(yaml_to_ts("config.yaml"))Java
Using Jackson (YAMLMapper) and Java code generation:
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.File;
public class YamlToTsExample {
public static void main(String[] args) throws Exception {
YAMLMapper mapper = new YAMLMapper();
JsonNode root = mapper.readTree(new File("config.yaml"));
System.out.println("export interface AppConfig {");
root.fields().forEachRemaining(entry -> {
String type = entry.getValue().isNumber() ? "number" : entry.getValue().isBoolean() ? "boolean" : "string";
System.out.println(" " + entry.getKey() + ": " + type + ";");
});
System.out.println("}");
}
}