0

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.

enter image description here

1
  • Refer to this MSDOC for Azure CLI az appconfig feature filter update Commented Dec 21, 2023 at 4:02

1 Answer 1

0

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:

{"Users":["user1","user2","user4","user3"],"Groups":[],"DefaultRolloutPercentage":50}

enter image description here

Using the below command I can able to update the az appconfig feature filter from the text file.

Command and output:

vexxxre:~$ file_content1=$(cat cli.txt)
venkxxxe:~$ echo "$file_content1"
{"Users":["user1","user2","user4","user3"],"Groups":[],"DefaultRolloutPercentage":50}
venkxxxx:~$ az appconfig feature filter update --connection-string <your-connection-string> --feature <Your-feature-name> --filter-name Microsoft.Targeting --filter-parameters Audience="$file_content1" --yes
This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
{
  "name": "Microsoft.Targeting",
  "parameters": {
    "Audience": {
      "DefaultRolloutPercentage": 50,
      "Groups": [],
      "Users": [
        "user1",
        "user2",
        "user4",
        "user3"
      ]
    }
  }
}

enter image description here

Portal:

enter image description here

Reference:

az appconfig feature filter | Microsoft Learn

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.