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

to kdl for formats

Converts structured data into KDL text.

Signature

> to kdl {flags}

Flags

  • --spec {int}: KDL language version (1 or 2 (default)).
  • --format {string}: Data model: 'jik' (default) for JSON-in-KDL, or 'nodes' for KDL AST rows.
  • --serialize, -s: Serialize nushell types that cannot be deserialized (shorthand for --non-roundtrip lossy).
  • --non-roundtrip {string}: How to handle values that are non-roundtrippable ('error' (default), 'null', or 'lossy').

Input/output types:

inputoutput
anystring

Examples

Convert a record to JSON-in-KDL (default KDL v2 keywords).

> {a: 1, b: true} | to kdl
- a=1 b=#true

Emit KDL v2 explicitly with --spec 2.

> {a: 1, b: true} | to kdl --spec 2
- a=1 b=#true

Emit KDL v1 keywords with --spec 1 (bare true/false/null).

> {a: 1, b: true} | to kdl --spec 1
- a=1 b=true

Convert a list to JSON-in-KDL.

> [1 2 3] | to kdl
- 1 2 3

Emit null/bool keywords as KDL v2.

> [null false true] | to kdl --spec 2
- #null #false #true

Emit null/bool keywords as KDL v1.

> [null false true] | to kdl --spec 1
- null false true

Round-trip KDL through node rows (default v2).

> 'node one; node two' | from kdl | to kdl
node one
node two

Round-trip a KDL v1 document; metadata keeps --spec 1 on to kdl.

> "item 1 enabled=true" | from kdl --spec 1 | to kdl
item 1 enabled=true

Round-trip a KDL v2 document with --spec 2 on both sides.

> "item 1 enabled=#true" | from kdl --spec 2 | to kdl --spec 2
item 1 enabled=#true

Override metadata: parse as v1 but emit as v2.

> "item 1 enabled=true" | from kdl --spec 1 | to kdl --spec 2
item 1 enabled=#true

Serialize a closure as a string.

> {|| 1 + 1} | to kdl --serialize
- "{|| 1 + 1}"

Emit Nushell filesize and duration with type annotations.

> {size: 1kib, wait: 5sec} | to kdl
- size=(filesize)1024 wait=(duration)5000000000

Emit a datetime as a (timestamp) annotation (RFC 3339 string).

> {when: 2020-01-02T03:04:05+00:00} | to kdl
- when=(timestamp)"2020-01-02T03:04:05+00:00"

Emit a cell-path with a (cell-path) annotation.

> $.1.abc | to kdl
- (cell-path)$.1.abc

Emit a range with a (range) annotation.

> 1..3 | to kdl
- (range)"1..3"

Emit a glob with a (glob) annotation.

> "*.rs" | into glob | to kdl
- (glob)*.rs

Emit binary data as base64 with a (binary) annotation.

> 0x[01 02 03] | to kdl
- (binary)AQID

Round-trip annotated Nushell types through KDL.

> {size: 1kib, wait: 5sec} | to kdl | from kdl --format jik
╭──────┬────────╮
│ size │ 1.0 kB │
│ wait │ 5sec   │
╰──────┴────────╯

Round-trip a list of records (table-shaped data) as JSON-in-KDL.

> [{a: 1}, {a: 2}] | to kdl | from kdl --format jik
╭───┬───╮
│ # │ a │
├───┼───┤
│ 0 │ 1 │
│ 1 │ 2 │
╰───┴───╯