---
schema_version: "1"
id: 8f009a0c9e87a5c2d693659106efd418ddf04b49820227a76e9f32b4625bf567
title: code-analyzer ast-dump
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/code-analyzer/cli_reference_code-analyzer_ast-dump.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_code-analyzer_ast-dump.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4e3e309788e588909ebc09a327ba8368603ffc1663c6df3ec9123407062799e1
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# code-analyzer ast-dump

Dump the Abstract Syntax Tree (AST) for a given source file.

## Description for code-analyzer ast-dump

Generate and display the AST that PMD produces when parsing a source file. This is useful for understanding how PMD interprets your code and for developing custom PMD rules. The command supports Apex, Visualforce, HTML, XML, and JavaScript files.

## Flags

| Flag Name (Long) | Flag Name (Short) | Description |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;file</code> | N/A | **Type:** Value<br>**Required**<br><br>Path to the source file to parse.<br><br>The file whose AST you want to generate. The file must exist and be a regular file (not a directory). If you don't specify the `--language` flag, the language is auto-detected from the file extension. |
| <code>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;format</code> | N/A | **Type:** Value<br>**Valid Values:** `json`, `xml`<br>**Default value:** `xml`<br><br>Output format for the AST.<br><br>Choose between `xml` (default) or `json`. The XML format outputs the raw PMD AST XML, preserving the full tree structure. The JSON format provides a flat array of nodes with names, attributes, parent, and ancestor information. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;language</code> | <code>&#8209;l</code> | **Type:** Value<br>**Valid Values:** `apex`, `visualforce`, `html`, `xml`, `javascript`<br>**Default value:** `apex`<br><br>Language of the source file.<br><br>Explicitly specify the language of the source file. Defaults to `apex`. Supported languages are: apex, visualforce, html, xml, and javascript. |
| <code>&#8209;&#8209;output&#8209;file</code> | N/A | **Type:** Value<br><br>Path to the file where the AST output is written.<br><br>If specified, the AST output is written to this file instead of being displayed in the terminal. The content format depends on the `--format` flag. |

## Examples for code-analyzer ast-dump

Dump the AST for an Apex class file in JSON format (default):

```shell
sf code-analyzer ast-dump --file ./force-app/main/default/classes/MyClass.cls
```

Dump the AST in XML format:

```shell
sf code-analyzer ast-dump --file ./force-app/main/default/classes/MyClass.cls --format xml
```

Dump the AST and write the output to a file:

```shell
sf code-analyzer ast-dump --file ./force-app/main/default/classes/MyClass.cls --output-file ast-output.json
```

Explicitly specify the language when the file extension is ambiguous:

```shell
sf code-analyzer ast-dump --file ./src/myfile.html --language html
```
<!-- prettier-ignore-end -->
