YAML Key Renamer

Rename object keys across YAML documents recursively or at root level. Update legacy schemas, refactor configuration names, and standardize property keys.

How to Use the YAML Key Renamer

1

Input YAML & Define Keys

Paste your YAML payload, enter the Old Key Name to replace, and specify the New Key Name.

2

Choose Renaming Scope

Select All Levels (Recursive) to update nested dictionaries or Root Level Only for top keys.

3

Live Renaming & Export

The tool renames keys in real time as you edit or adjust options. Click Copy or Download to save your updated YAML.

Tool Options

Recursive & Root Scope

Choose between renaming keys across all deeply nested objects and arrays or strictly targeting top-level root properties.

Case-Sensitive & Insensitive Matching

Perform precise exact-case key matching or case-insensitive matching to normalize camelCase, PascalCase, or snake_case.

Structure & Value Safety

Safely renames mapping keys without modifying property values, string contents, array elements, or boolean flags.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the YAML Key Renamer do?

The YAML Key Renamer on blueutils.com renames object and dictionary property keys across YAML configuration files, Kubernetes manifests, and cloud documents. It supports recursive deep replacement across all nested mappings and arrays, root-level scoping, and exact or case-insensitive matching while preserving values, data types, and formatting.

Core Concepts

Understanding key replacement behaviors in YAML documents:

  • Recursive vs. Root Scope: Recursive renaming updates the target key in every nested dictionary and sequence of objects. Root-only scoping targets top-level properties without touching nested child objects.
  • Case Matching Options: Exact matching (exact) matches the precise case of the old key, while case-insensitive matching (case-insensitive) updates keys irrespective of casing variations (camelCase, PascalCase, or snake_case).
  • Data Integrity Preservation: Property values, string payloads, array ordering, numbers, and boolean types remain strictly unchanged during key transformation.

How to use the tool?

  1. Paste or Upload YAML Payload: Paste your YAML configuration into the left Raw YAML Input editor, click Upload, or click Sample.
  2. Specify Keys & Options: Enter the Old Key Name to replace and the New Key Name to set. Choose your Scope (All Levels or Root Only) and Case Sensitivity.
  3. Instant Renaming & Export: Keys are renamed in real time as you type or change options. Click Copy to copy the renamed YAML or Download to save your updated blueutils-renamed.yaml file.

Related Developer Utilities

If you work with YAML refactoring, key manipulation, and schema migrations, explore these related tools:

  • YAML Sorter: Alphabetically sort YAML keys recursively for clean Git diffs.
  • YAML Formatter: Prettify and format YAML documents with custom indentation rules.
  • YAML Diff Tool: Compare and inspect semantic differences between two YAML files side-by-side.
  • YAML to JSON Converter: Convert YAML configuration files into standardized JSON documents.

REST API Integration

blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/rename-key) to programmatically rename property keys across YAML payloads.

API Request Parameters

Name Type Description Example
rawText / yaml String / Object / Array Raw YAML configuration string or object. "server:\n host: localhost\n port: 8080"
oldKey String Target key name to search and replace. "host"
newKey String New key name to assign. "hostname"
scope String (Optional) Replacement scope: "all" (default) or "root". "all"
matchMode String (Optional) Case matching: "exact" (default) or "case-insensitive". "exact"
indent Number/String (Optional) Indentation spacing: 2 (default) or 4. 2

API Request Payload Examples

cURL (Using Raw String)

curl -X POST https://blueutils.com/api/yaml/rename-key \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "server:\n  host: localhost\n  port: 8080\ndatabase:\n  host: db.internal",
    "oldKey": "host",
    "newKey": "hostname",
    "scope": "all"
  }'

cURL (Using Direct Object)

curl -X POST https://blueutils.com/api/yaml/rename-key \
  -H "Content-Type: application/json" \
  -d '{
    "yaml": {
      "server": { "host": "localhost", "port": 8080 }
    },
    "oldKey": "host",
    "newKey": "hostname"
  }'

Python

import requests

url = "https://blueutils.com/api/yaml/rename-key"
payload = {
    "rawText": "server:\n  host: localhost\n  port: 8080\ndatabase:\n  host: db.internal",
    "oldKey": "host",
    "newKey": "hostname",
    "scope": "all"
}
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": "server:\\n  host: localhost\\n  port: 8080",
                "oldKey": "host",
                "newKey": "hostname",
                "scope": "all"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/yaml/rename-key"))
            .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 key renaming succeeded. true
message String Confirmation message returned when renaming succeeds. "Successfully renamed 2 key occurrences in YAML document."
renamedYaml String Updated YAML document with keys renamed. "server:\n hostname: localhost\n port: 8080"
data Object / Array Parsed native representation of the YAML document. {"server":{"hostname":"localhost"}}
replacementsCount Number Total count of key replacements executed. 2
originalSize Number Byte size of raw input payload in UTF-8. 54
resultSize Number Byte size of updated YAML output in UTF-8. 58
error String Summary error description (when isValid is false). "Invalid input: Target old key name cannot be empty."

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "message": "Successfully renamed 2 key occurrences in YAML document.",
  "renamedYaml": "server:\n  hostname: localhost\n  port: 8080\ndatabase:\n  hostname: db.internal",
  "data": {
    "server": {
      "hostname": "localhost",
      "port": 8080
    },
    "database": {
      "hostname": "db.internal"
    }
  },
  "replacementsCount": 2,
  "originalSize": 54,
  "resultSize": 58
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Invalid input: Target old key name 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 rename YAML keys?

Integrating the YAML key renamer API into migration scripts, schema refactoring tools, and continuous delivery pipelines provides concrete advantages:

  • Automated Schema Migration: Seamlessly rename deprecated configuration properties across hundreds of microservice manifests during version upgrades.
  • Config Standardization: Harmonize naming conventions (e.g. converting uri to url or dbHost to db_host) across disparate YAML deployment templates.
  • Optimized Token Efficiency for AI Agents: AI assistants can rename keys across large YAML documents with a single API request instead of regenerating massive configuration bodies token-by-token.

Native Usage

How to rename YAML keys locally in terminal environments:

Windows (CMD / PowerShell)

# Rename YAML key using Python in PowerShell
python -c "
import yaml

def rename_key(obj, old_k, new_k):
    if isinstance(obj, dict):
        return { (new_k if k == old_k else k): rename_key(v, old_k, new_k) for k, v in obj.items() }
    if isinstance(obj, list):
        return [rename_key(i, old_k, new_k) for i in obj]
    return obj

data = yaml.safe_load(open('config.yaml'))
updated = rename_key(data, 'host', 'hostname')
with open('config.renamed.yaml', 'w') as f:
    yaml.dump(updated, f, default_flow_style=False)
print('Key renamed successfully.')
"

Linux / Unix (Bash)

# Rename YAML key using yq
yq '.. |= with(select(has("host")), .hostname = .host | del(.host))' config.yaml > config.renamed.yaml

Python

Using PyYAML:

import yaml

def rename_keys_deep(data, old_key, new_key):
    if isinstance(data, dict):
        return {
            (new_key if k == old_key else k): rename_keys_deep(v, old_key, new_key)
            for k, v in data.items()
        }
    elif isinstance(data, list):
        return [rename_keys_deep(item, old_key, new_key) for item in data]
    return data

with open("config.yaml", "r") as f:
    raw_data = yaml.safe_load(f)

updated_data = rename_keys_deep(raw_data, "host", "hostname")
with open("config.renamed.yaml", "w") as f:
    yaml.dump(updated_data, f, default_flow_style=False)

print("Key renamed successfully.")

Java

Using Jackson with YAMLMapper:

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.File;
import java.util.Iterator;
import java.util.Map;

public class YamlKeyRenamerExample {
    public static void renameKey(JsonNode node, String oldKey, String newKey) {
        if (node.isObject()) {
            ObjectNode obj = (ObjectNode) node;
            if (obj.has(oldKey)) {
                JsonNode value = obj.get(oldKey);
                obj.remove(oldKey);
                obj.set(newKey, value);
            }
            Iterator<JsonNode> elements = obj.elements();
            while (elements.hasNext()) {
                renameKey(elements.next(), oldKey, newKey);
            }
        } else if (node.isArray()) {
            for (JsonNode child : node) {
                renameKey(child, oldKey, newKey);
            }
        }
    }

    public static void main(String[] args) throws Exception {
        YAMLMapper mapper = new YAMLMapper();
        JsonNode root = mapper.readTree(new File("config.yaml"));
        renameKey(root, "host", "hostname");
        mapper.writeValue(new File("config.renamed.yaml"), root);

        System.out.println("YAML key renamed successfully.");
    }
}

Frequently Asked Questions (FAQ)

How do I rename a key across a YAML document?

Enter your YAML data, specify the existing key name in Old Key Name, enter the desired replacement in New Key Name, and click Rename YAML Key. The document will be updated immediately.

Can I rename keys across deeply nested objects and arrays?

Yes. Setting the Scope to All Levels (Recursive) renames the target key throughout all nested dictionaries, arrays of maps, and child configurations.

Does the tool support case-insensitive key replacement?

Yes. Select Case Insensitive to match and replace keys regardless of whether they are camelCase, PascalCase, or snake_case.

Are property values or string contents altered when renaming keys?

No. Only mapping property keys matching the target name are replaced; all scalar values, array items, numbers, and boolean states remain unmodified.

Is my YAML data secure when renaming keys online?

Yes. All YAML parsing and key replacement operations execute 100% client-side directly within your browser. Your configurations and secrets are never transmitted to any server.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.