to json

For formats.

Converts table data into JSON text.

Command Type

built-in

Signature

> to json {flags}

Flags

  • --raw, -r: Remove all of the whitespace and trailing line ending.
  • --indent, -i {number}: Specify indentation width.
  • --tabs, -t {number}: Specify indentation tab quantity.
  • --serialize, -s: Serialize nushell types that cannot be deserialized.

Input/output types:

input output
any string

Examples

Outputs a JSON string, with default indentation, representing the contents of this table.

> [a b c] | to json
[
  "a",
  "b",
  "c"
]

Outputs a JSON string, with 4-space indentation, representing the contents of this table.

> [Joe Bob Sam] | to json --indent 4
[
    "Joe",
    "Bob",
    "Sam"
]

Outputs an unformatted JSON string representing the contents of this table.

> [1 2 3] | to json -r
[1,2,3]

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.