yq
v4.x
v4.x
  • yq
  • How It Works
  • Recipes
  • Upgrading from V3
  • Commands
    • Evaluate
    • Evaluate All
    • Shell Completion
  • Operators
    • Add
    • Alternative (Default value)
    • Anchor and Alias Operators
    • Array to Map
    • Assign (Update)
    • Boolean Operators
    • Collect into Array
    • Column
    • Comment Operators
    • Compare Operators
    • Contains
    • Create, Collect into Object
    • Date Time
    • Delete
    • Divide
    • Document Index
    • Encode / Decode
    • Entries
    • Env Variable Operators
    • Equals
    • Eval
    • File Operators
    • Filter Operator
    • Flatten
    • Group By
    • Has
    • Keys
    • Kind
    • Length
    • Line
    • Load
    • Min
    • Map
    • Max
    • Modulo
    • Multiply (Merge)
    • Omit
    • Parent
    • Path
    • Pick
    • Pipe
    • Pivot
    • Recursive Descent (Glob)
    • Reduce
    • Reverse
    • Select
    • Shuffle
    • Slice Array
    • Sort
    • Sort Keys
    • Split into Documents
    • String Operators
    • Style
    • Subtract
    • Tag
    • To Number
    • Traverse (Read)
    • Union
    • Unique
    • Variable Operators
    • With
  • Usage
    • Output format
    • Working with CSV, TSV
    • Working with JSON
    • Working with Properties
    • Working with XML
    • Working with LUA
    • Working with TOML
    • Working with Shell Output
    • Front Matter
    • Split into multiple files
    • GitHub Action
    • Tips, Tricks, Troubleshooting
  • Github Page
Powered by GitBook
On this page
  • Parse: Simple
  • Parse: Deep paths
  • Encode: Scalar
  • Parse: inline table
  • Parse: Array Table
  • Parse: Empty Table

Was this helpful?

  1. Usage

Working with TOML

Decode from TOML. Note that yq does not yet support outputting in TOML format (and therefore it cannot roundtrip)

Parse: Simple

Given a sample.toml file of:

A = "hello"
B = 12

then

yq -oy '.' sample.toml

will output

A: hello
B: 12

Parse: Deep paths

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

Encode: Scalar

Given a sample.toml file of:

person.name = "hello"
person.address = "12 cat st"

then

yq '.person.name' sample.toml

will output

hello

Parse: inline table

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

Parse: Array Table

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

Parse: Empty Table

Given a sample.toml file of:


[dependencies]

then

yq -oy '.' sample.toml

will output

dependencies: {}
PreviousWorking with LUANextWorking with Shell Output

Last updated 1 year ago

Was this helpful?