JSON Key-Value Swapper

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

Input JSON

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 JSON

How to Use

  1. Enter or paste your flat JSON 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 JSON.
  4. The result will appear in the output field on the right.
  5. Use "Copy to Clipboard" or "Download JSON" to save your result.

Examples & Info

Basic Example

Input:

{"name": "John", "age": "30"}

Output:

{"John": "name", "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 JSON
  • • 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

About JSON Key-Value Swapper

This tool swaps the keys and values in a flat JSON 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 JSON structures.

Related Tools