0

This is the json object:

{
    "aaa": "111",
    "bbb": "222",
    "ccc": [{
        "ddd ": "333",
        "eee": "444"
    }]
}

Currently this is working when I run the program in windows cmd:

MyProgram.py --myJSON "{ \"aaa\": \"111\", \"bbb\": \"222\", \"ccc\": [{ \"ddd\": \"333\", \"eee\": \"444\" }] }"

Is it possible to give in a JSON object as a string without '\' character?

Kroy
  • 299
  • 1
  • 5
  • 18

1 Answers1

2

You need the \ character to escape your string since you're using double quotes. Try this:

MyProgram.py --myJSON '{ "key": "value", ... }'

Of course, now you will need to use backslashes to escape single quotes. A better way to pass JSON into your program would be to store it in a file and then load it:

with open('my_json.json', 'r') as f:
    json = f.read()
print json
Terrence
  • 194
  • 1
  • 12