> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/management-and-administration/api-best-practices/examples/export-flag-definitions.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Export all feature flag definition JSON structures

Learn how to export all feature flag definitions' JSON structure in all environments and workspaces using the Admin API.

## Overview <a href="#overview" id="overview"></a>

Use this script to export all feature flag definitions' JSON structure in all environments and workspaces to a file named `[Workspace Name]_[Environment Name]_[Split Name].json`.

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* Install the [Python Admin API Wrapper](https://developer.harness.io/feature-management-experimentation/management-and-administration/api-best-practices/wrappers/python-admin-api.md).
* You have created an Admin API key from the Harness FME UI.

## Configuration <a href="#configuration" id="configuration"></a>

Before running the script, update the following variables in the code:

* `ADMIN API KEY`: Your Admin API key.
* `workspaceName`: The name of the workspace.
* `environmentName`: The name of the environment.
* `targetFolder`: The directory where the JSON file lives.

Run this script using Python 3 from your local machine or preferred development environment.

```python
from splitapiclient.main import get_client

#############################################
workspaceName = "Defaults"
environmentName = "Production"
targetFolder="/Users/bilalal-shahwany/Desktop/WeWork/"
#############################################

def SaveToFile(splitDefinition, splitName, workspaceName, environmentName):
    reportObj = open(targetFolder+workspaceName+"_"+environmentName+"_"+splitName+".json", "w")
    json.dump(splitDefinition, reportObj)
    reportObj.close()

ws = client.workspaces.find(workspaceName)
env = client.environments.find(environmentName, ws.id)
for splitDef in client.split_definitions.list(env.id, ws.id):
   print ("Exporting Split: "+splitDef._name)
   trs = []
   for tr in splitDef._treatments:
      trs.append(tr.export_dict())
   rls = []
   for rl in splitDef._rules:
      rls.append(rl.export_dict()) 
   drls = []
   for drl in splitDef._default_rule:
      drls.append(drl.export_dict()) 
   splitDefinition = {"treatments": trs,"defaultTreatment": splitDef._default_treatment, "rules": rls, "defaultRule": drls}
   SaveToFile(splitDefinition, splitDef._name, ws._name, env._name)
```

## Next steps

* Go to [Export feature flag treatments to a YAML file](https://developer.harness.io/feature-management-experimentation/management-and-administration/api-best-practices/examples/export-treatments.md) to export flag treatments to a YAML file.
* Go to [Copy and overwrite feature flag definitions between environments](https://developer.harness.io/feature-management-experimentation/management-and-administration/api-best-practices/examples/copy-flag-definition.md) to copy flag definitions between environments.

{% @harness-feedback/feedback %}
