Exporting Templates and Converting Them to Bicep
This lesson explains the two ways to export templates and how to convert between JSON and Bicep.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish between exporting from a resource group and from deployment history.
- Describe how to decompile JSON to Bicep and build Bicep to JSON.
Exporting templates
There are two export sources with different results. Export template on a resource group or a selection of resources generates a template from the resources' current state, in ARM JSON or Bicep. It captures resources however they were created, including manual changes, but the output usually needs cleaning: values are hard-coded unless Include parameters is selected, some resource types and properties cannot be exported (the portal lists warnings), and read-only properties may be included. Up to 200 resources can be exported at once.
Exporting from deployment history (the Deployments page, Template tab, or az deployment group export) returns the original template that was deployed, with its parameters and expressions intact, but it does not include changes made after the deployment or resources created by other means. Exported templates can be downloaded, added to a library or saved as template specs.
The following diagram shows the steps from the resource group to a tested Bicep file.

Which export source?
Converting between JSON and Bicep
az bicep decompile --file template.json (or bicep decompile) converts an ARM JSON template to a .bicep file. Decompilation is best-effort: complex expressions may produce warnings, and symbolic names generated from resource names may need renaming, so the result should be reviewed and tested with what-if. az bicep build --file main.bicep does the opposite, producing the ARM JSON that Resource Manager deploys. In Visual Studio Code, the Bicep extension can decompile a file and paste JSON as Bicep. The steps below summarize a typical migration.
-
Export
Export the resource group's template (or take the existing JSON template).
-
Decompile
Run az bicep decompile to create a .bicep file.
-
Clean up
Fix warnings, add parameters for hard-coded values, remove read-only properties and rename symbolic names.
-
Validate
Run what-if against the existing resource group and confirm that no unexpected changes appear.
From hand-built resources to Bicep
Capturing a hand-built environment
A test environment of a VNet, two VMs and a load balancer was built manually in the portal over several months, with many configuration changes. The team wants a Bicep file that recreates it in another region. What should the administrator do?
Use Export template on the resource group, choosing Bicep (or JSON followed by az bicep decompile), because the export reflects the resources' current state including all manual changes. Then parameterize the location and names, and test with what-if. Exporting from deployment history would return only the original portal deployments without the later changes.
Which command converts an ARM JSON template to a Bicep file?
Show answer
az bicep decompile.
Exam Tips
Remember for the exam
- Export from a resource group captures current state; from deployment history, the original template.
- az bicep decompile converts JSON to Bicep; az bicep build converts Bicep to JSON.
- Exported templates usually need parameters added and warnings fixed.
- Validate converted templates with what-if.