pkg/yqlib/doc/usage/toml.md
Decode from TOML. Note that yq does not yet support outputting in TOML format (and therefore it cannot roundtrip)
Given a sample.toml file of:
A = "hello"
B = 12
then
yq -oy '.' sample.toml
will output
A: hello
B: 12
Given a sample.toml file of:
person.name = "hello"
person.address = "12 cat st"
then
yq -oy '.' sample.toml
will output
person:
name: hello
address: 12 cat st
Given a sample.toml file of:
person.name = "hello"
person.address = "12 cat st"
then
yq '.person.name' sample.toml
will output
hello
Given a sample.toml file of:
name = { first = "Tom", last = "Preston-Werner" }
then
yq -oy '.' sample.toml
will output
name:
first: Tom
last: Preston-Werner
Given a sample.toml file of:
[owner.contact]
name = "Tom Preston-Werner"
age = 36
[[owner.addresses]]
street = "first street"
suburb = "ok"
[[owner.addresses]]
street = "second street"
suburb = "nice"
then
yq -oy '.' sample.toml
will output
owner:
contact:
name: Tom Preston-Werner
age: 36
addresses:
- street: first street
suburb: ok
- street: second street
suburb: nice
Given a sample.toml file of:
[[fruits]]
name = "apple"
[[fruits.varieties]] # nested array of tables
name = "red delicious"
then
yq -oy '.' sample.toml
will output
fruits:
- name: apple
varieties:
- name: red delicious
Given a sample.toml file of:
[dependencies]
then
yq -oy '.' sample.toml
will output
dependencies: {}
Given a sample.toml file of:
name = { first = "Tom", last = "Preston-Werner" }
then
yq '.' sample.toml
will output
name = { first = "Tom", last = "Preston-Werner" }
Given a sample.toml file of:
[owner.contact]
name = "Tom"
age = 36
then
yq '.' sample.toml
will output
[owner.contact]
name = "Tom"
age = 36
Given a sample.toml file of:
[[fruits]]
name = "apple"
[[fruits.varieties]]
name = "red delicious"
then
yq '.' sample.toml
will output
[[fruits]]
name = "apple"
[[fruits.varieties]]
name = "red delicious"
Given a sample.toml file of:
A = ["hello", ["world", "again"]]
B = 12
then
yq '.' sample.toml
will output
A = ["hello", ["world", "again"]]
B = 12
Given a sample.toml file of:
A = "hello"
B = 12
then
yq '.' sample.toml
will output
A = "hello"
B = 12
Given a sample.toml file of:
[person]
name = "hello"
address = "12 cat st"
then
yq '.' sample.toml
will output
[person]
name = "hello"
address = "12 cat st"
Given a sample.toml file of:
A = []
then
yq '.' sample.toml
will output
A = []
Given a sample.toml file of:
var = "x"
[owner.contact]
name = "Tom Preston-Werner"
age = 36
then
yq '.' sample.toml
will output
var = "x"
[owner.contact]
name = "Tom Preston-Werner"
age = 36
Given a sample.toml file of:
[dependencies]
then
yq '.' sample.toml
will output
[dependencies]
Given a sample.toml file of:
# This is a comment
A = "hello" # inline comment
B = 12
# Table comment
[person]
name = "Tom" # name comment
then
yq '.' sample.toml
will output
# This is a comment
A = "hello" # inline comment
B = 12
# Table comment
[person]
name = "Tom" # name comment
Given a sample.toml file of:
# This is a TOML document
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [8000, 8001, 8002]
data = [["delta", "phi"], [3.14]]
temp_targets = { cpu = 79.5, case = 72.0 }
# [servers] yq can't do this one yet
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
then
yq '.' sample.toml
will output
# This is a TOML document
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [8000, 8001, 8002]
data = [["delta", "phi"], [3.14]]
temp_targets = { cpu = 79.5, case = 72.0 }
# [servers] yq can't do this one yet
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
Given a sample.yml file of:
arg:
hello: foo
then
yq -o toml '.' sample.yml
will output
[arg]
hello = "foo"