I'm trying to change my whole json object using etcdctl:
etcdctl put /var/dir "{"key1" : "value1", "key2": "value2"}"
And after this idk how, but this json become invalid, quotes are cutted:
etcdctl get /var/dir
{key1 : value1, key2: value2}
How can i avoid this problem?
As @Gereon mentioned, you need to use bracketing single quotes to pass JSON to etcd. (The same is true in using JSON with
curl
). The JSON spec calls for double quotes, so you need to ensure you keep valid double quote pairs within the JSON - containing the entire JSON with double quotes messes that up.The command
etcdctl put /var/dir "{"key1" : "value1", "key2": "value2"}"
, when passed to etcd will not be understood as JSON - etcd will put a single string into the value, which is what you're seeing when youetcdctl get
Now surround your JSON with a matched pair of single quotes:
$ etcdctl put /var/dir '{"key1" : "value1", "key2": "value2"}'
and you'll see the difference more obviously:
$ etcdctl get /var/dir