jsonconsulconsul-kv

Import Key Value Pair from Json File Consul


I am new to Consul.

I am trying to import a key/value pair from Json File. (working in windows env)

But when I try to import with the following command, facing error.

Command:

consul.exe kv import @keyvalue.json

Contents:

{"MYVAR": "123","AnotherKey":"SomeValueHere"}

Error:

Cannot unmarshal data: json: cannot unmarshal object into Go value of type []*command.kvExportEntry

Could any one suggest some ideas, in solving this error.

Thanks.


Solution

  • Ah,

    Got it.

    We have throw the json in this following format.

    [        {
                    "key": "europe",
                    "flags": 0,
                    "value": "NzQzLjE="
            },
            {
                    "key": "europe/france",
                    "flags": 0,
                    "value": "NjYuOQ=="
            },
            {
                    "key": "europe/germany",
                    "flags": 0,
                    "value": "ODIuNjc="
            }
    ]
    

    Reference from: http://alesnosek.com/blog/2017/07/15/first-look-at-the-key-value-store-in-consul/

    Thx.