Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

record walk for filters

Run a closure on every value nested inside a record, rebuilding the record from the results.

Command Type

built-in

Signature

> record walk {flags} (closure)

Flags

  • --containers, -c: Also run the closure on each nested record and list, after its contents have been walked.
  • --no-lists: Do not descend into lists; pass each list to the closure as a single value.

Parameters

  • closure: The closure to run on each nested value.

Input/output types:

inputoutput
recordrecord
tabletable
list<any>list<any>

Examples

Multiply every number in a nested record.

> {a: 1, b: {c: 2, d: [3, 4]}} | record walk {|value| $value * 10}
╭───┬────────────────────╮
│ a │ 10                 │
│   │ ╭───┬────────────╮ │
│ b │ │ c │ 20         │ │
│   │ │   │ ╭───┬────╮ │ │
│   │ │ d │ │ 0 │ 30 │ │ │
│   │ │   │ │ 1 │ 40 │ │ │
│   │ │   │ ╰───┴────╯ │ │
│   │ ╰───┴────────────╯ │
╰───┴────────────────────╯

Redact every value whose cell path mentions a password.

> {user: alice, auth: {password: abc, expires: 2026}} | record walk {|value, path| if ($path | to text) =~ password { '***' } else { $value } }
╭──────┬─────────────────────╮
│ user │ alice               │
│      │ ╭──────────┬──────╮ │
│ auth │ │ password │ ***  │ │
│      │ │ expires  │ 2026 │ │
│      │ ╰──────────┴──────╯ │
╰──────┴─────────────────────╯

Unwrap every record that holds only a value field, innermost first.

> {a: {value: 1}, b: {c: {value: {value: 2}}}} | record walk --containers {|value| match $value { {value: $x} if ($value | columns) == [value] => $x, _ => $value } }
╭───┬───────────╮
│ a │ 1         │
│   │ ╭───┬───╮ │
│ b │ │ c │ 2 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

Sort every list without visiting its items.

> {tags: [c a b], nested: {ids: [3 1 2]}} | record walk --no-lists {|value| if ($value | describe) starts-with list { $value | sort } else { $value } }
╭────────┬─────────────────────╮
│        │ ╭───┬───╮           │
│ tags   │ │ 0 │ a │           │
│        │ │ 1 │ b │           │
│        │ │ 2 │ c │           │
│        │ ╰───┴───╯           │
│        │ ╭─────┬───────────╮ │
│ nested │ │     │ ╭───┬───╮ │ │
│        │ │ ids │ │ 0 │ 1 │ │ │
│        │ │     │ │ 1 │ 2 │ │ │
│        │ │     │ │ 2 │ 3 │ │ │
│        │ │     │ ╰───┴───╯ │ │
│        │ ╰─────┴───────────╯ │
╰────────┴─────────────────────╯

Double every number in each row of a table.

> [{a: 1, b: {c: 2}} {a: 3, b: {c: 4}}] | record walk {|value| $value * 2}
╭───┬───┬───────────╮
│ # │ a │     b     │
├───┼───┼───────────┤
│ 0 │ 2 │ ╭───┬───╮ │
│   │   │ │ c │ 4 │ │
│   │   │ ╰───┴───╯ │
│ 1 │ 6 │ ╭───┬───╮ │
│   │   │ │ c │ 8 │ │
│   │   │ ╰───┴───╯ │
╰───┴───┴───────────╯

Notes

The closure receives each leaf value and the cell path that leads to it from the top of the record. The value is also passed as $in. Nested records and lists are descended into, and every other value is a leaf. Empty records and lists hold no leaves, so they are kept as they are. With --containers, the closure also runs on each nested record and list after its contents have been walked, so it sees the updated container. The input record itself is never passed to the closure. With --no-lists, lists are treated as leaves and passed to the closure whole. Given a list of records, each record is walked on its own, with cell paths starting at that record, and the results are streamed.