1

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?

dan k
  • 41
  • 6
  • Is this a shell command? If so, you need to escape the quotes so that the shell does not remove them, e.g. by enclosing the whol string in single quotes `'` – Gereon Feb 20 '23 at 11:44
  • Yes, I'm using gitbash terminal, just tryed to use single quotes and get: bash: {keys:: command not found – dan k Feb 20 '23 at 11:45

1 Answers1

0

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"}
James_SO
  • 1,169
  • 5
  • 11