What does the YAML to Java Properties Converter do?
The YAML to Java Properties Converter converts hierarchical application.yml and nested YAML documents into flat, dot-notated Java application.properties key-value pairs. It recursively traverses nested maps and indexed YAML lists, converting them into standard Java property keys (such as spring.datasource.url and app.servers[0].host) while escaping newlines and special characters.
Core Concepts
Understanding YAML to Java properties flattening rules:
- Recursive Tree Flattening: Traverses multi-level nested YAML structures and concatenates keys with dot delimiters (
server.port=8080). - List Index Formatting: Converts YAML list items into array index notation (e.g.
allowed-origins[0]=https://example.com). - Character Escaping: Escapes newline breaks and carriage returns (
\n,\r) to adhere to standard Java.propertiesspecification rules.
How to use the tool?
- Paste YAML Configuration: Enter or paste your
application.ymlor nested YAML document into the editor or click Sample. - Real-time Live Flattening: Flattens dynamically into dot-notated properties in real time without clicking extra buttons.
- Copy & Save: Click Copy or Download to save your flattened
application.propertiesfile.
Related Developer Utilities
If you work with Spring Boot configurations, Java properties, and YAML tools, explore these complementary tools:
- Java Properties to YAML Converter: Convert Java properties back into hierarchical YAML.
- YAML Formatter & Beautifier: Clean and re-indent YAML configuration files.
- YAML to JSON Converter: Convert YAML documents into JSON payloads.
- YAML Syntax Validator: Check YAML indentation and locate syntax violations.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/yaml-to-properties) to programmatically flatten nested YAML and application.yml files into standard Java .properties format.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String / Object | YAML content to flatten into dot notation or parsed JS object (aliases: rawYaml, yaml, data, payload, input, text). |
"spring:\n datasource:\n url: jdbc:h2:mem" |
includeHeader |
Boolean | Whether to prepend comment header metadata (default true). |
true |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/yaml/yaml-to-properties \
-H "Content-Type: application/json" \
-d '{
"rawText": "spring:\n datasource:\n url: jdbc:postgresql://localhost:5432/mydb\nserver:\n port: 8080"
}'Python
import requests
url = "https://blueutils.com/api/yaml/yaml-to-properties"
payload = {
"rawText": "spring:\n datasource:\n url: jdbc:postgresql://localhost:5432/mydb\nserver:\n port: 8080"
}
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": "spring:\\n datasource:\\n url: jdbc:postgresql://localhost:5432/mydb\\nserver:\\n port: 8080"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/yaml/yaml-to-properties"))
.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 conversion succeeded. | true |
propertyCount |
Number | Count of generated dot-notation property lines. | 2 |
converted |
String | Flattened Java properties file content. | "spring.datasource.url=...\nserver.port=8080" |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"propertyCount": 2,
"converted": "spring.datasource.url=jdbc:postgresql://localhost:5432/mydb\nserver.port=8080"
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid YAML syntax: unexpected end of stream"
}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 properties?
Integrating the YAML to Properties API into build tools, CI/CD runners, or automated configuration migration scripts offers key advantages:
- Rapid Script Validation: Converts modern Spring Boot YAML into flat key-value pairs required by legacy Java frameworks and container runtime environment loaders.
- Optimized Token Efficiency for AI Agents: LLMs often miss keys when manually unnesting large YAML files. Calling the API extracts all property paths deterministically with zero token overhead.
- Deterministic Accuracy Without Hallucinations: Ensures 100% accurate key flattening and array indexing without property omissions.
Native Usage
How to convert YAML to Java properties locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Flatten YAML into properties using Python in PowerShell
python -c "
import yaml
def flatten(d, prefix=''):
for k, v in d.items():
key = f'{prefix}.{k}' if prefix else k
if isinstance(v, dict): flatten(v, key)
else: print(f'{key}={v}')
with open('application.yml') as f:
flatten(yaml.safe_load(f))
"Linux / Unix (Bash)
# Flatten YAML into properties using Python in Linux
python3 -c "
import yaml
def flatten(d, prefix=''):
for k, v in d.items():
key = f'{prefix}.{k}' if prefix else k
if isinstance(v, dict): flatten(v, key)
else: print(f'{key}={v}')
with open('application.yml') as f:
flatten(yaml.safe_load(f))
"Python
Using Python yaml:
import yaml
def flatten_dict(d, prefix=''):
items = []
for k, v in d.items():
key = f"{prefix}.{k}" if prefix else k
if isinstance(v, dict):
items.extend(flatten_dict(v, key))
elif isinstance(v, list):
for i, item in enumerate(v):
items.extend(flatten_dict(item, f"{key}[{i}]") if isinstance(item, dict) else [f"{key}[{i}]={item}"])
else:
items.append(f"{key}={v}")
return items
with open('application.yml', 'r') as f:
data = yaml.safe_load(f)
print("\n".join(flatten_dict(data)))Java
Using Java and SnakeYAML:
import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream;
import java.util.Map;
public class YamlToPropertiesExample {
public static void flatten(Map<String, Object> map, String prefix) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = prefix.isEmpty() ? entry.getKey() : prefix + "." + entry.getKey();
if (entry.getValue() instanceof Map) {
flatten((Map<String, Object>) entry.getValue(), key);
} else {
System.out.println(key + "=" + entry.getValue());
}
}
}
public static void main(String[] args) throws Exception {
Yaml yaml = new Yaml();
try (FileInputStream in = new FileInputStream("application.yml")) {
Map<String, Object> data = yaml.load(in);
flatten(data, "");
}
}
}