A lightweight CLI tool for extracting values from TOML using path expressions. Specify multiple paths — the first match wins.
go install github.com/stephenc-ori/toml-get@latesttoml-get [flags] <path> [path...]
Multiple paths are tried in order; the first match is printed. Exits with status 1 if no path matches.
| Flag | Default | Description |
|---|---|---|
-f <file> |
stdin | Input TOML file |
-o <format> |
raw |
Output format: raw, toml, or json |
Segments are separated by dots. Each segment is a bare key, a TOML basic-quoted key, or a TOML literal-quoted key. Array indices use bracket notation.
| Path | Description |
|---|---|
. |
Entire document |
key |
Top-level bare key |
a.b.c |
Nested bare keys |
a[0] |
Array index |
a[0].b |
Array index then nested key |
"key.with.dot" |
Basic-quoted key (supports \n \t \\ \" \uXXXX \UXXXXXXXX) |
'key.with.dot' |
Literal-quoted key (verbatim, no escape processing) |
a."b.c"[0].'d.e' |
Mix of bare, basic-quoted, index, and literal-quoted |
Keys with dots, spaces, or other special characters in their names must be quoted.
| Format | Description |
|---|---|
raw |
Plain value — strings unquoted, scalars as-is, complex types as JSON |
toml |
TOML literal — strings double-quoted, tables as TOML, arrays as TOML arrays |
json |
JSON — works for any value type |
Given config.toml:
title = "My App"
version = 2
[database]
host = "db.example.com"
port = 5432
[[servers]]
name = "web-1"
ip = "10.0.0.1"
[[servers]]
name = "web-2"
ip = "10.0.0.2"# Simple value
toml-get -f config.toml title
# My App
# Nested value
toml-get -f config.toml database.host
# db.example.com
# Array index
toml-get -f config.toml 'servers[0].name'
# web-1
# First match wins — useful for fallbacks
toml-get -f config.toml override.host database.host
# db.example.com
# JSON output
toml-get -f config.toml -o json database
# {
# "host": "db.example.com",
# "port": 5432
# }
# TOML output
toml-get -f config.toml -o toml database
# host = "db.example.com"
# port = 5432
# Read from stdin
cat config.toml | toml-get database.port
# 5432
# Keys with dots in their names — quote them
toml-get -f config.toml '"server.host"'
toml-get -f config.toml "'server.host'"The tomlget package can be used directly:
import "github.com/stephenc-ori/toml-get/tomlget"
data, err := tomlget.Parse(r)
// Single path
val, ok := tomlget.Get(data, "database.host")
// First match from multiple paths
val, ok := tomlget.GetFirst(data, []string{"override.host", "database.host"})
// Format the result
out, err := tomlget.Format(val, tomlget.FormatJSON)MIT