---
title: ast
categories: |
debug
version: 0.104.0
debug: |
Print the abstract syntax tree (ast) for a pipeline.
usage: |
Print the abstract syntax tree (ast) for a pipeline.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->
# `ast` for [debug](/commands/categories/debug.md)
<div class='command-title'>Print the abstract syntax tree (ast) for a pipeline.</div>
## Signature
```> ast {flags} (pipeline)```
## Flags
- `--json, -j`: Serialize to json
- `--minify, -m`: Minify the nuon or json output
- `--flatten, -f`: An easier to read version of the ast
## Parameters
- `pipeline`: The pipeline to print the ast for.
## Input/output types:
| input | output |
| ------- | ------ |
| nothing | table |
## Examples
Print the ast of a string
```nu
> ast 'hello'
```
Print the ast of a pipeline
```nu
> ast 'ls | where name =~ README'
```
Print the ast of a pipeline with an error
```nu
> ast 'for x in 1..10 { echo $x '
```
Print the ast of a pipeline with an error, as json, in a nushell table
```nu
> ast 'for x in 1..10 { echo $x ' --json | get block | from json
```
Print the ast of a pipeline with an error, as json, minified
```nu
> ast 'for x in 1..10 { echo $x ' --json --minify
```
Print the ast of a string flattened
```nu
> ast "'hello'" --flatten
╭───┬─────────┬──────────────┬───────────────╮
│ # │ content │ shape │ span │
├───┼─────────┼──────────────┼───────────────┤
│ 0 │ 'hello' │ shape_string │ ╭───────┬───╮ │
│ │ │ │ │ start │ 0 │ │
│ │ │ │ │ end │ 7 │ │
│ │ │ │ ╰───────┴───╯ │
╰───┴─────────┴──────────────┴───────────────╯
```
Print the ast of a string flattened, as json, minified
```nu
> ast "'hello'" --flatten --json --minify
[{"content":"'hello'","shape":"shape_string","span":{"start":0,"end":7}}]
```
Print the ast of a pipeline flattened
```nu
> ast 'ls | sort-by type name -i' --flatten
╭───┬─────────┬────────────────────┬────────────────╮
│ # │ content │ shape │ span │
├───┼─────────┼────────────────────┼────────────────┤
│ 0 │ ls │ shape_external │ ╭───────┬───╮ │
│ │ │ │ │ start │ 0 │ │
│ │ │ │ │ end │ 2 │ │
│ │ │ │ ╰───────┴───╯ │
│ 1 │ | │ shape_pipe │ ╭───────┬───╮ │
│ │ │ │ │ start │ 3 │ │
│ │ │ │ │ end │ 4 │ │
│ │ │ │ ╰───────┴───╯ │
│ 2 │ sort-by │ shape_internalcall │ ╭───────┬────╮ │
│ │ │ │ │ start │ 5 │ │
│ │ │ │ │ end │ 12 │ │
│ │ │ │ ╰───────┴────╯ │
│ 3 │ type │ shape_string │ ╭───────┬────╮ │
│ │ │ │ │ start │ 13 │ │
│ │ │ │ │ end │ 17 │ │
│ │ │ │ ╰───────┴────╯ │
│ 4 │ name │ shape_string │ ╭───────┬────╮ │
│ │ │ │ │ start │ 18 │ │
│ │ │ │ │ end │ 22 │ │
│ │ │ │ ╰───────┴────╯ │
│ 5 │ -i │ shape_flag │ ╭───────┬────╮ │
│ │ │ │ │ start │ 23 │ │
│ │ │ │ │ end │ 25 │ │
│ │ │ │ ╰───────┴────╯ │
╰───┴─────────┴────────────────────┴────────────────╯
```