JSON to TOML Tutorial: Convert JSON Objects to TOML Tables
TOML is designed for configuration files. JSON objects map well to TOML key-value pairs and tables, but not every JSON value has a TOML equivalent. The biggest limitation is JSONnull.
Convert a flat JSON object to TOML
{
"name": "jsonic",
"version": "1.0.0",
"private": true,
"retries": 3
}name = "jsonic"
version = "1.0.0"
private = true
retries = 3Convert nested objects to TOML tables
Nested JSON objects usually become TOML tables.
{
"server": {
"host": "localhost",
"port": 8080
},
"database": {
"poolSize": 10
}
}[server]
host = "localhost"
port = 8080
[database]
poolSize = 10Convert arrays of objects to array tables
JSON arrays that contain objects map naturally to TOML array tables.
{
"plugins": [
{ "name": "auth", "enabled": true },
{ "name": "billing", "enabled": false }
]
}[[plugins]]
name = "auth"
enabled = true
[[plugins]]
name = "billing"
enabled = falseHandle JSON null before converting
TOML does not support null. Replace null fields with a real default, remove them, or choose a sentinel string that your app understands.
// JSON input that needs cleanup
{
"theme": null,
"enabled": true
}
// TOML-safe version
{
"enabled": true
}When JSON to TOML conversion works best
- The root JSON value is an object, not an array.
- Nested objects represent configuration sections.
- Arrays contain primitives or similarly shaped objects.
- The data does not need null values.
- The output will be edited by humans as config.
Common JSON to TOML mistakes
- Trying to convert arbitrary API payloads instead of config-like objects.
- Leaving null values in the input.
- Using mixed-type arrays that are hard for config consumers to interpret.
- Expecting TOML to preserve JSON object key order as business logic.
Convert JSON to TOML online
Use Jsonic's JSON to TOML converter to transform config-like JSON into TOML tables and array tables in your browser.
Open JSON to TOML