I have the following environment variable that I have included in my azure-pipelines.yaml file:
- name: myVariable
value: '{"key1":"value1","key2":"value2"}'
The problem is the way that the pipeline is passing along this variable. When echoed, it looks like this: key1:value1 key2:value2
, and since my application is expecting a JSON string, this is throwing JSONDecodeError("Extra data", s, end).
I tried formatting the variable differently with escape characters as follows:
{"key1":"value1","key2":"value2"}
which resulted in this echoed variable as I would expect:
{"key1":"value1","key2":"value2"}
but my application code threw this error JSONDecodeError: Expecting property name enclosed in double quotes. I added double quotes as follows:
"{"key1":"value1","key1":"value1"}"
but then received the following error: While parsing a quoted scalar, find unknown escape character.
It seems like the pipeline file doesn’t like the format of the variable. I’m wondering if there is an issue with the way that I have formatted the variable. I’d like for the variable to be passed the way I have described above, but if all else fails I could pass it in a more agreeable format and have my application code parse it. Would appreciate any thoughts, thanks.
2
Answers
Did you try this?
"{"key1":"value1","key2":"value2"}"
Not sure how your application invokes the json. Check the variable doc:
you could use convertToJson expression, it takes a complex object and outputs it as JSON.
output:
If you use it for variable:
Output:
You could check to use parameter or variable for definition, and invoke
${MY_JSON}
in your application.