The SDK for Azure Policy supports this action.
- Azure CLI
- Azure PowerShell
There are SDK for other languages also, such as REST API, .NET, JavaScript, and Python.
All of the Azure CLI and Azure PowerShell operations and cmdlets can be run with no parameters to get all available objects (built-ins and custom for definitions) that the authenticated user has access to without any parameters.
]
Then you can loop through the results and convert them to JSON files:
This approach also means you could filter the resulting definitions if you didn't want a specific category or something along those lines: