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
  • Get kind
  • Get kind, ignores custom tags
  • Add comments only to scalars

Was this helpful?

  1. Operators

Kind

The kind operator identifies the type of a node as either scalar, map, or seq.

This can be used for filtering or transforming nodes based on their type.

Note that null values are treated as scalar.

Get kind

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true
f: []
g: {}
h: null

then

yq '.. | kind' sample.yml

will output

map
scalar
scalar
scalar
scalar
seq
map
scalar

Get kind, ignores custom tags

Unlike tag, kind is not affected by custom tags.

Given a sample.yml file of:

a: !!thing cat
b: !!foo {}
c: !!bar []

then

yq '.. | kind' sample.yml

will output

map
scalar
map
seq

Add comments only to scalars

An example of how you can use kind

Given a sample.yml file of:

a:
  b: 5
  c: 3.2
e: true
f: []
g: {}
h: null

then

yq '(.. | select(kind == "scalar")) line_comment = "this is a scalar"' sample.yml

will output

a:
  b: 5 # this is a scalar
  c: 3.2 # this is a scalar
e: true # this is a scalar
f: []
g: {}
h: null # this is a scalar
PreviousKeysNextLength

Last updated 8 months ago

Was this helpful?