A simple and elegant JSON to TOML converter API built with Elixir and Phoenix.
Tomlify is a lightweight web service that converts JSON data to TOML format. It provides a simple HTTP API endpoint that accepts JSON input and returns properly formatted TOML output.
- Simple API: Single endpoint for JSON to TOML conversion
- Robust: Comprehensive test coverage with 40+ tests
- Type Support: Handles strings, numbers, booleans, null values, arrays, and nested objects
- TOML Tables: Automatically converts nested JSON objects to TOML tables
- Health Check: Built-in health check endpoint for monitoring
- Quality Tooling: Includes Credo, Dialyzer, and automated formatting
- Elixir 1.14 or higher
- Erlang/OTP 24 or higher
- Clone the repository:
git clone https://github.com/pivattogui/tomlify
cd tomlify- Install dependencies:
mix deps.get- Run the application:
mix phx.serverThe server will start on http://localhost:4000
Endpoint: POST /convert
Content-Type: application/json
Request Body: Any valid JSON object
Response: Plain text TOML format
curl -X POST http://localhost:4000/convert \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "age": 30, "active": true}'Response:
name = "John Doe"
age = 30
active = truecurl -X POST http://localhost:4000/convert \
-H "Content-Type: application/json" \
-d '{
"title": "My App",
"database": {
"host": "localhost",
"port": 5432
}
}'Response:
title = "My App"
[database]
host = "localhost"
port = 5432curl -X POST http://localhost:4000/convert \
-H "Content-Type: application/json" \
-d '{"tags": ["elixir", "phoenix", "toml"], "scores": [95, 87, 92]}'Response:
tags = ["elixir", "phoenix", "toml"]
scores = [95, 87, 92]curl -X POST http://localhost:4000/convert \
-H "Content-Type: application/json" \
-d '{
"app_name": "MyApp",
"version": "1.0.0",
"features": ["auth", "api"],
"server": {
"host": "0.0.0.0",
"port": 4000
},
"database": {
"adapter": "postgresql",
"pool_size": 10
}
}'Response:
app_name = "MyApp"
version = "1.0.0"
features = ["auth", "api"]
[server]
host = "0.0.0.0"
port = 4000
[database]
adapter = "postgresql"
pool_size = 10Endpoint: GET /health
Response:
{
"status": "ok",
"service": "tomlify",
"timestamp": "2025-11-29T12:00:00Z"
}Run all tests:
mix testRun the complete quality check suite:
mix qualityThis runs:
- Code formatting check
- Credo static analysis
- Dialyzer type checking
- All tests
Format code:
mix formatRun Credo:
mix credo --strictRun Dialyzer:
mix dialyzerThe project follows Phoenix's standard structure with a few key components:
Tomlify.Converter- Core conversion logicTomlifyWeb.ConvertController- HTTP endpoint handlerTomlifyWeb.HealthController- Health check endpoint
The converter implements a simple TOML encoder that:
- Separates top-level values from nested objects
- Encodes simple key-value pairs first
- Creates TOML table sections for nested objects
- Handles various data types (strings, numbers, booleans, arrays, null)
tomlify/
├── config/ # Application configuration
├── lib/
│ ├── tomlify/
│ │ ├── application.ex # OTP application
│ │ └── converter.ex # JSON to TOML conversion logic
│ ├── tomlify_web/
│ │ ├── controllers/
│ │ │ ├── convert_controller.ex
│ │ │ ├── health_controller.ex
│ │ │ └── error_json.ex
│ │ ├── endpoint.ex
│ │ ├── router.ex
│ │ └── telemetry.ex
│ └── tomlify.ex
├── test/ # Test files
│ ├── tomlify/
│ │ └── converter_test.exs # Unit tests
│ └── tomlify_web/
│ └── controllers/
│ ├── convert_controller_test.exs # Integration tests
│ └── health_test.exs
├── mix.exs # Project dependencies
└── README.md
The project has comprehensive test coverage including:
- Simple values (strings, numbers, booleans, null)
- Arrays (strings, numbers, mixed types, empty)
- Nested maps (TOML tables)
- Edge cases (empty maps, special characters)
- Error handling (invalid inputs)
- Complex scenarios (realistic configurations)
- HTTP endpoint behavior
- Content-Type handling
- Various JSON structures
- Response format validation
Total: 40 tests, 0 failures
SECRET_KEY_BASE- Phoenix secret key (required in production)PHX_HOST- Application host (default: example.com)PORT- HTTP port (default: 4000)DNS_CLUSTER_QUERY- DNS cluster query for distributed deployments
MIX_ENV=prod mix releasePHX_SERVER=true _build/prod/rel/tomlify/bin/tomlify startThe current implementation has the following limitations:
- Does not support deeply nested TOML tables (nested within nested)
- Does not support TOML array of tables syntax
- Does not support inline tables
- Does not escape special characters in strings (quotes, backslashes, etc.)
- Does not support TOML datetime types
These are intentional design decisions to keep the implementation simple and focused on common use cases.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project follows standard Elixir conventions:
- Run
mix formatbefore committing - Ensure
mix qualitypasses - Add tests for new features
- Update documentation as needed
This project is available as open source under the terms of the MIT License.
For issues, questions, or contributions, please open an issue on GitHub.
Built with: