https://prefect.io logo
Title
e

Erick Joca

09/26/2022, 11:28 AM
Hello, guys! I believe I´ve found an unexpected behavior that obligates us to use scapes in JSON parameter. I´m running Prefect 2.4.1 under Windows 11. To reproduce the error, just try something similiar this command: prefect deployment build testetalend.py:talend --name talend_deploy --apply --params='{"job_name": "myjobname", "batch_file": "C:/Users/myuser/Documents/testeTalend/myscript.bat"}' After hit Enter, we got this message: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) To workarround the problem, type de same command using scapes in JSON string: prefect deployment build testetalend.py:talend --name talend_deploy --apply --params='{\"job_name\": \"myjobname\", \"batch_file\": \"C:/Users/myuser/Documents/testeTalend/myscript.bat\"}' Anyway, this behavior is very similar that was reported by the issue below: https://github.com/PrefectHQ/prefect/issues/3295 Thanks in advance!
1
j

Jeff Hale

09/26/2022, 12:36 PM
I think you need to escape the forward slash character in JSON,
/
, so you you should only need to escape those parts of the file path. See more here.
r

Ryan Peden

09/26/2022, 1:22 PM
A forward slash should be okay inside a string in JSON. It looks like this is caused by the way
cmd
(and PowerShell too, I believe) processes double quote characters. If this is
cmd
, using two double quote characters at either end of the JSON might also work:
--params=""{"job_name": "myjobname", "batch_file":"C:/Users/myuser/Documents/testeTalend/myscript.bat"}""
👍 1
e

Erick Joca

09/27/2022, 6:20 PM
Hi, Guys! Let´s try a more simple example. Please, take a look at this small piece of code: --------------------------------------------------------------------------- from prefect import task, flow, get_run_logger import sys @task def log_name(job_name): logger = get_run_logger() logger.info(f'*** MY NAME IS - {job_name} ***') @flow def test_parameter(job_name : str): log_name(job_name) if name == "__main__": test_parameter(sys.argv[1]) --------------------------------------------------------------------------- Now that's all the results using the params option in CLI: 1) JSON parameter with no scapes delimited by single quotation marks prefect deployment build testparameter.py:test_parameter --name test_parameter_deploy --apply --params='{"job_name": "HELLO!"}' -> Error (json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)) 2) JSON parameter with no scapes delimited by double quotation marks prefect deployment build testparameter.py:test_parameter --name test_parameter_deploy --apply --params=""{"job_name": "HELLO!"}"" -> Error (Unexpected token ':' in expression or statement) 3) JSON parameter using scapes delimited by single quotation marks prefect deployment build testparameter.py:test_parameter --name test_parameter_deploy --apply --params='{\"job_name\": \"HELLO!\"}' -> It works!!!
r

Ryan Peden

09/27/2022, 6:25 PM
Thanks for the extra information, Erick! Are you using
cmd
or PowerShell?
e

Erick Joca

09/27/2022, 6:32 PM
Vscode´s terminal
using cmd we got the same behavior