TOML Formatter

Format and beautify TOML. Note: comments are lost and key order may change (@iarna/toml limitation)

Key Facts

Category
Conversion & Encoding
Input Types
textarea, number, select
Output Type
text
Sample Coverage
1
API Ready
Yes

Overview

The TOML Formatter is a utility designed to clean up, beautify, or minify your TOML configuration files. It parses your input and outputs structured, readable TOML, though please note that comments are removed and the order of keys may change during processing.

When to Use

  • When you need to clean up messy or poorly indented TOML configuration files for projects like Rust or Python.
  • When you want to minify TOML data to reduce file size for storage or transmission.
  • When validating the syntax of a TOML snippet to ensure it parses correctly without syntax errors.

How It Works

  • Paste your raw TOML configuration text into the TOML Input area.
  • Select your formatting mode, choosing either Beautify to format with indentation or Minify to compress the output.
  • Adjust the indentation size if needed, then run the formatter to generate the clean TOML output.

Use Cases

Beautifying a cluttered Cargo.toml file for a Rust project to improve readability.
Minifying pyproject.toml configurations to save space in automated deployment pipelines.
Checking and fixing indentation inconsistencies in Hugo static site generator configuration files.

Examples

1. Beautifying a Rust Cargo.toml File

Rust Developer
Background
A developer has a messy Cargo.toml file with inconsistent spacing, mixed indentation, and unaligned keys.
Problem
The configuration file is hard to read and maintain during code reviews.
How to Use
Paste the messy Cargo.toml content into the TOML Input field, set the Mode to Beautify, set Indent Size to 2, and run the formatter.
Example Config
Mode: Beautify, Indent Size: 2
Outcome
The TOML is cleanly formatted with consistent indentation, making it easy to read, though comments are removed.

2. Minifying a Hugo Site Configuration

DevOps Engineer
Background
A DevOps engineer wants to reduce the size of a large config.toml file used in a static site deployment pipeline.
Problem
The configuration file contains unnecessary whitespace and line breaks that increase the payload size.
How to Use
Paste the config.toml content into the input area, change the Mode to Minify, and process the input.
Example Config
Mode: Minify
Outcome
The TOML is compressed into a single-line or compact format, stripping out all unnecessary whitespace.

Try with Samples

format-conversion

Related Hubs

FAQ

Why did my comments disappear after formatting?

The underlying parser does not preserve comments during the parsing and serialization process.

Why did the order of my keys change?

The formatter parses TOML into an internal data structure where key order is not guaranteed to remain identical to the input.

Can I minify my TOML file using this tool?

Yes, you can switch the mode option from Beautify to Minify to compress your TOML data.

What indentation sizes are supported?

You can configure the indentation size from 0 to 8 spaces, with 2 spaces being the default standard.

Does this tool validate TOML syntax?

Yes, if the input TOML contains syntax errors, the formatter will fail to parse it and will display an error message.

API Documentation

Request Endpoint

POST /en/api/tools/toml-formatter

Request Parameters

Parameter Name Type Required Description
tomlInput textarea Yes -
indentSize number No -
mode select No -

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-toml-formatter": {
      "name": "toml-formatter",
      "description": "Format and beautify TOML. Note: comments are lost and key order may change (@iarna/toml limitation)",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=toml-formatter",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]