I am trying to store a map like structure on consul key/value
Example under path a/b/c
I want to store
[“a”->1,“b”->2] such mapping
or either I can store enum with value like
Value(0,“a”)
Is this possible ?
Hi @newcoder4010,
Consul’s KV supports storing arbitrary data. As such, you can store anything from JSON or YAML documents to binary objects.
Here’s a short example of how you can store a JSON object/map structure at a specific key in the KV store.
{
"a": 1,
"b": 2
}
Upload the data to Consul by performing an HTTP PUT against the /kv/
API with the desired key name.
$ curl --request PUT "$CONSUL_HTTP_ADDR/v1/kv/my-data" --data @map.json
true
Read this data back by performing an HTTP GET. The data is returned as a Base64-encoded value which must be decoded to obtain the original JSON document.
$ curl --silent $CONSUL_HTTP_ADDR/v1/kv/my-data | jq '.[].Value | @base64d | fromjson'
{
"a": 1,
"b": 2
}