toml
stableLightweight TOML parser and serializer: parse a TOML string or file into a Zolo table, and convert a table back to a TOML string.
use plugin toml::{parse, stringify, parse_file} Plugin snippets can be edited in the Playground, but native capabilities are executed locally with the Zolo CLI.
Functions (3)
From import to result
- 01Import only what you use
- 02Copy the smallest example
- 03Run it with the Zolo CLI
Parse a TOML string into a table
Parses a TOML-formatted string and returns it as a Zolo table. TOML arrays become integer-keyed tables; TOML tables become string-keyed tables. Datetime values are returned as strings.
use plugin toml::{parse}
let config = parse('[server]\nhost = "localhost"\nport = 8080')
print(config["server"]["host"])
print(config["server"]["port"])Serialize a table to a TOML string
Serializes a Zolo table to a pretty-printed TOML string. Integer-keyed tables are serialized as TOML arrays; string-keyed tables become TOML tables.
use plugin toml::{parse, stringify}
let data = #{"name": "myapp", "version": "1.0", "debug": false}
let toml_str = stringify(data)
print(toml_str)Read and parse a TOML file from disk
Reads the file at path and parses its contents as TOML. Raises an error if the file cannot be read or contains invalid TOML.
use plugin toml::{parse_file}
let config = parse_file("config/settings.toml")
print(config["database"]["url"])