YAML Key-Value Swapper

A simple, fast and free online tool to swap keys and values in flat YAML objects

Input YAML

Configuration Options

Duplicate Value Handling

Value Type Handling

If unchecked, non-primitive values will cause an error

Ensures all new keys are valid strings

Output YAML

How to Use

  1. Enter or paste your flat YAML object in the input field on the left.
  2. Configure the options based on your needs:
    • Duplicate handling: Choose how to handle multiple keys with the same value
    • Value types: Configure how to handle non-primitive values
  3. Click the "Swap Keys & Values" button to process your YAML.
  4. The result will appear in the output field on the right.
  5. Use "Copy to Clipboard" or "Download YAML" to save your result.

Examples & Info

Basic Example

Input:

firstName: John
lastName: Doe
age: 30

Output:

John: firstName
Doe: lastName
'30': age

Duplicate Values (Group Mode)

Input:

a: '1'
b: '1'
c: '2'

Output:

'1':
  - a
  - b
'2': c

Validation Rules

  • • Input must be valid YAML
  • • Input must be an object (not array or primitive)
  • • Values become keys, so they must be valid
  • • Null values are skipped
  • • Boolean/number values are converted to strings

Use Cases

  • • Reverse lookup tables
  • • Configuration file transformations
  • • Data structure inversions
  • • API response transformations
  • • YAML to YAML transformations

About YAML Key-Value Swapper

This tool swaps the keys and values in a flat YAML object, creating a reverse mapping. It's particularly useful for:

The tool includes robust error handling and configuration options to handle edge cases like duplicate values, non-primitive types, and invalid YAML structures. Output is generated in standard block style YAML format.

Related Tools