This works in python shell, but not when I execute it with python -c
, what is the syntax error here?
I need to update just one value in file myjson.json
python3.6 -c "import json; with open('myjson.json', 'r+') as jsonFile: data = json.load(jsonFile); data['root']['target']['branch'][0] = 'updated_value'; jsonFile.seek(0); json.dump(data, jsonFile, indent=4); jsonFile.truncate()"
File "<string>", line 1
import json; with open('myjson.json', 'r+') as jsonFile: data = json.load(jsonFile); data['root']['target']['branch'][0] = 'updated_value'; jsonFile.seek(0); json.dump(data, jsonFile, indent=4); jsonFile.truncate()
^
SyntaxError: invalid syntax