I'm trying to extract information from a text file and store the content in a variable using the Azure CLI command below.
file_content=$(cat /home/diwakar/cli.txt)
echo $file_content
After running the above command, the following output was obtained (Same content I have cli.txt file):
Output:
Audience={"Users":["user1","user2","user4","user3"],"Groups":[],"DefaultRolloutPercentage":50}
When I run the actual command, the variable takes on a different value, leading to an error.
az appconfig feature filter update --connection-string $endpoint --feature $featurename --filter-name Microsoft.Targeting --filter-parameters $file_content --yes
Below is the error message:
Filter parameter value must be a JSON escaped string. "{"Users":["user1","user2","user4","user3"],"Groups":[],"DefaultRolloutPercentage":50}" is not a valid JSON object.
The above error occurred due to the value of the
$file_content
variable is not a valid JSON object. This is because the value of the$file_content
variable is being interpreted as a string literal, rather than a JSON object.In my environment, I set the
cli.txt
as below:Using the below command I can able to update the az appconfig feature filter from the text file.
Command and output:
Portal:
Reference:
az appconfig feature filter | Microsoft Learn