---
schema_version: "1"
id: 97ff9367a00a9e4195be0e5d8cb4ea2fdf6e620871a42db4ff3ca343036f5559
title: data export tree
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/data/cli_reference_data_export_tree.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_data_export_tree.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: f6fe5b523aea598063d980fcde5ca9121054ad7535e1558c26b4757942452a44
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# data export tree

Export data from an org into one or more JSON files.

## Description for data export tree

Specify a SOQL query, either directly at the command line or read from a file, to retrieve the data you want to export. The exported data is written to JSON files in sObject tree format, which is a collection of nested, parent-child records with a single root record. Use these JSON files to import data into an org with the "sf data import tree" command.

If your SOQL query references multiple objects, the command generates a single JSON file by default. You can specify the --plan flag to generate separate JSON files for each object and a plan definition file that aggregates them. You then specify just this plan definition file when you import the data into an org.

The SOQL query can return a maximum of 2,000 records. For more information, see the REST API Developer Guide. (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm).

## Aliases for data export tree

`force:data:tree:export`

## Flags

| Flag Name (Long) | Flag Name (Short) | Description |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;api&#8209;version</code> | N/A | **Type:** Value<br><br>Override the api version used for api requests made by this command |
| <code>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;output&#8209;dir</code> | <code>&#8209;d</code> | **Type:** Value<br><br>Directory in which to generate the JSON files; default is current directory. |
| <code>&#8209;&#8209;plan</code> | <code>&#8209;p</code> | **Type:** Boolean<br><br>Generate multiple sObject tree files and a plan definition file for aggregated import. |
| <code>&#8209;&#8209;prefix</code> | <code>&#8209;x</code> | **Type:** Value<br><br>Prefix of generated files. |
| <code>&#8209;&#8209;query</code> | <code>&#8209;q</code> | **Type:** Value<br>**Required**<br><br>SOQL query, or filepath of a file that contains the query, to retrieve records. |
| <code>&#8209;&#8209;target&#8209;org</code> | <code>&#8209;o</code> | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set. |

## Examples for data export tree

Export records retrieved with the specified SOQL query into a single JSON file in the current directory; the command uses your default org:

```shell
sf data export tree --query "SELECT Id, Name, (SELECT Name, Address__c FROM Properties__r) FROM Broker__c"
```

Export data using a SOQL query in the "query.txt" file and generate JSON files for each object and a plan that aggregates them:

```shell
sf data export tree --query query.txt --plan
```

Prepend "export-demo" before each generated file and generate the files in the "export-out" directory; run the command on the org with alias "my-scratch":

```shell
sf data export tree --query query.txt --plan --prefix export-demo --output-dir export-out --target-org my-scratch
```
<!-- prettier-ignore-end -->
