to kdl for formats
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:
| input | output |
|---|---|
| any | string |
Examples
Convert a record to JSON-in-KDL (default KDL v2 keywords).
> {a: 1, b: true} | to kdl
- a=1 b=#trueEmit KDL v2 explicitly with --spec 2.
> {a: 1, b: true} | to kdl --spec 2
- a=1 b=#trueEmit KDL v1 keywords with --spec 1 (bare true/false/null).
> {a: 1, b: true} | to kdl --spec 1
- a=1 b=trueConvert a list to JSON-in-KDL.
> [1 2 3] | to kdl
- 1 2 3Emit null/bool keywords as KDL v2.
> [null false true] | to kdl --spec 2
- #null #false #trueEmit null/bool keywords as KDL v1.
> [null false true] | to kdl --spec 1
- null false trueRound-trip KDL through node rows (default v2).
> 'node one; node two' | from kdl | to kdl
node one
node twoRound-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=trueRound-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=#trueOverride metadata: parse as v1 but emit as v2.
> "item 1 enabled=true" | from kdl --spec 1 | to kdl --spec 2
item 1 enabled=#trueSerialize 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)5000000000Emit 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.abcEmit 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)*.rsEmit binary data as base64 with a (binary) annotation.
> 0x[01 02 03] | to kdl
- (binary)AQIDRound-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 │
╰───┴───╯