I have a script that is called from another process that receives an input that is a json string.
import sys
import json
script_name, json_in = sys.argv
my json in looks something like:
'{"key1":"val1", "key2":[val2, val3], "key3":"val4"}'
when i print what is received by python and stored in json_in
it looks like:
{key1:val1, key2:[val2, val3], key:val4}
stepping through the pdb when i get to json_in
it's value is:
"'{key:val1, key2:[val2, vale3], key:val4}'"
i wasn't having this problem on Ubuntu, but when i use the same script on Windows it no longer works.
The script does work if you copy and paste the exact same input that is being passed to argv. So the only conclusion i've been able to come to is that argv is somehow stripping the double quotes? I haven't found any documentation that might describe why this is happening (especially when it works on Ubuntu).
Does anyone know why its being stripped?
The python function is being called by javascript function, but even if i just call the python scipt from the terminal using
>>> python file_name.py '{"key1":"val1", "key2":[val2, val3], "key3":"val4"}'
I get the same error. If you set the json_in
variable to the same value, or call it in the exact same way in the Ubuntu terminal, then there is no problem.