8 unstable releases (3 breaking)
Uses new Rust 2024
| 0.4.0 | Sep 22, 2025 |
|---|---|
| 0.3.1 | Jul 17, 2025 |
| 0.3.0 | Mar 27, 2025 |
| 0.2.3 | Mar 20, 2025 |
| 0.1.1 | Sep 28, 2024 |
#365 in Parser implementations
176 downloads per month
29KB
573 lines
tomli
tomli is a format preserving command-line tool for querying and editing TOML files.
This project is currently under development and the command-line interface can change at any time.
Installation
Using Cargo
cargo install tomli
Release tarball
wget https://github.com/blinxen/tomli/releases/download/$VERSION/tomli.tar.gz
Usage
By default, tomli will read from stdin unless --filepath is specified.
Query expressions
tomli tries to use the same syntax as jq for query expressions.
The following expressions are currently supported:
- Key and table identifier paths, e.g
foo.baror.(whole document) - Array indices, e.g.
foo[0]orfoo.bar[0][1]
Query TOML files
Examples:
Get the value of the name key from the package table:
tomli query -f Cargo.toml package.name
Get the first element of the array called bin:
tomli query -f Cargo.toml bin[0]
Edit TOML files
tomli currently supports the following types when setting a value:
- str (String)
- int (64-bit signed integer)
- float (64-bit floating point)
- bool (Boolean)
- datetime (RFC3339)
The value type can be specified with the --type argument.
If not type is specified, then str is used.
Examples:
Add a new key to the package table called website:
tomli set -f Cargo.toml package.website https://example.com
Set the name of the first element in the bin array to tumli:
tomli set -f Cargo.toml bin[0].name tumli
Add a new table called website to the first element of the bin array:
tomli set -f Cargo.toml bin[0].website.url https://example.com
Add a new array called websites to the table package:
tomli set -f Cargo.toml package.websites[0] https://example.com
Add a new array called numbers to the table package and specify the type:
tomli set -f Cargo.toml --type int package.numbers[0] 5
Use dotted key notation instead of creating a subtable:
tomli set -f Cargo.toml --dotted-key --type bool package.version.workspace true
Delete name in the table package:
tomli delete -f Cargo.toml package.name
Delete the first element in the array authors:
tomli delete -f Cargo.toml package.authors[0]
License
The source code is primarily distributed under the terms of the MIT License. See LICENSE for details.
Dependencies
~2–2.9MB
~53K SLoC