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 you etcdctl 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
/var/dir
{"key1" : "value1", "key2": "value2"}