1

so I am trying to write a yaml for an ADO pipeline which therefore uses ADO syntax. But somehow within the process some " get lost and I don't know why. So here's my yaml file:

parameters:
  - name: dictionary
    type: string
    default: '{\"PartitionKey\": \"test\", \"RowKey\":\"test1\"}'

steps:
- script: |
    echo ${{ parameters.dictionary }}
- task: PythonScript@0
  inputs:
    scriptSource: 'filePath'
    scriptPath: path/table.py
    arguments: --output_parameters ${{ parameters.dictionary }}

The output of echo ${{ parameters.dictionary }} is {"PartitionKey": "test", "RowKey":"test1"}

Within my python script the output of print(args.output_parameters) is {\PartitionKey": "test", "RowKey":"test1"}

and the error message is the following because I try to gain a dictionary (my_entity= json.loads(args.output_parameters)):

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

So why is there a \ instead of a " in front of the first key "PartitionKey" even though it seemed to work fine for all other key value pairs?

Bondgirl
  • 107
  • 7

1 Answers1

0

Maybe this answer can help:

Single quotes let you put almost any character in your string, and won't try to parse escape codes. '\n' would be returned as the string \n

Alessio
  • 85
  • 10
  • 1
    Hmmm, I am not sure since that is exactly what I did, right? My overall string is in single quotes for exact that reason since json demands the key and values to be in double quotes. – Bondgirl Aug 03 '23 at 12:27
  • hmmm yes, with pure python and argparse it works. Is argparse set correctly in the table.py script? – Alessio Aug 03 '23 at 12:40
  • Yes. It also works for me when I run the python script locally on my machine using this "args":["--output_parameters","{\"PartitionKey\": \"test\",\"RowKey\": \"test1\"}" Also tried to give everything in double quotes within the yaml "{\"PartitionKey\": \"test\", \"RowKey\":\"test2\"}", but then even more is missing from my string.... [--output_parameters OUTPUT_PARAMETERS] table.py: error: unrecognized arguments: test, RowKey:test2 – Bondgirl Aug 03 '23 at 14:44