Error occurred while converting Bicep deployment output to JSON in Azure pipeline

Naveen Kumar (NVK) 20 Reputation points
2025-12-15T12:41:43.5866667+00:00

We are encountering the following error when trying to convert the Bicep deployment output to JSON.

Error:

convertFrom-Json : Conversion from JSON failed with error: Unexpected character encountered while parsing value: B. Path '', line 0, position 0.

User's image

Bicep deployment task:

  • task: AzureCLI@2
                name: IacDeploy
    
                displayName: "Deploy Bicep template"
    
                inputs:
    
                  azureSubscription: "DEV_sub"
    
                  scriptType: pscore
    
                  scriptLocation: "inlineScript"
    
                  inlineScript: |
    
                    az config set bicep.use_binary_from_path=false
    
                    az bicep upgrade
    
                    $result = az deployment sub create `
    
                        --name $(Build.BuildNumber) `
    
                        --location ${{lower(variables.location)}} `
    
                        --template-file '$(Pipeline.Workspace)/drop/${{lower(variables.iacTemplatePath)}}' `
    
                        --parameters '$(Pipeline.Workspace)/drop/${{lower(variables.iacTemplateParametersPath)}}' `
    
    					  | ConvertFrom-Json
    

Kindly help us in resolving this case.

Azure DevOps
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Naveen Kumar (NVK) 20 Reputation points
    2025-12-16T06:36:22.1+00:00

    Hi,

    Removed ConvertFrom-Json from create command and added to the show command and it was started working as expected.

    Could you please help us to know why "ConvertFrom-Json" wasn't worked on Create command.

    $resultBicep = az deployment sub create `
                              --name $(Build.BuildNumber) `
                              --location ${{lower(variables.location)}} `
                              --template-file '$(Pipeline.Workspace)/drop/${{lower(variables.iacTemplatePath)}}' `
                              --parameters '$(Pipeline.Workspace)/drop/${{lower(variables.iacTemplateParametersPath)}}' 
    
                          $result = az deployment sub show --name $(Build.BuildNumber) | ConvertFrom-Json
    
                          $resourceGroupName = $result.properties.outputs.resourceGroupName.value
                          Write-Host "##vso[task.setvariable variable=resourceGroupName]$resourceGroupName"  
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.