Key value mapping for an array of json

pxzxz1
New Member

How to use KVM API for array of json?

[
  {"name": "Vanessa Ashley", "colour": "Pink", "sport": "Running"},
  {"name": "Lucas Kylo", "colour": "Brown", "sport": "Football"},
  {"name": "Michelle Kristine", "colour": "Gray", "sport": "Badminton"},
  {"name": "Noah Oliver", "colour": "Yellow", "sport": "Basketball"}
]

0 5 1,065
5 REPLIES 5

I guess what you want to do is, use the KVM API to store a JSON as a KVM value. Is that right?

And it just happens that the JSON is an array of objects (hashes). Is that right?

You want to POST to MGMTSERVER/ v1/ o/ ORG/ e/ ENV/ keyvaluemaps/ MAP/ entries/ key1

...where key1 is the key name. The payload should be application/json like this:

{
  "name" : "key1",
  "value" : "[{\"name\":\"Vanessa Ashley\",\"colour\":\"Pink\",\"sport\":\"Running\"},{\"name\":\"Lucas Kylo\",\"colour\":\"Brown\",\"sport\":\"Football\"},{\"name\":\"Michelle Kristine\",\"colour\":\"Gray\",\"sport\":\"Badminton\"},{\"name\":\"Noah Oliver\",\"colour\":\"Yellow\",\"sport\":\"Basketball\"}]"
}

It doesn't matter. This is how you set the payload for an environment-specific KVM, but it doesn't matter which one you use. The payload is the same. i think You originally asked "how can I structure the payload" and I gave that answer, and whether it is env or org or proxy scoped, the payload is the same.

If only one API proxy requires data in a KVM, you can create the KVM at the apiproxy scope, where only that API proxy can access the data.

If all API proxies in your test environment to have access to a key value map, in which case you'd create a key value map at the environment scope. Proxies deployed in the "prod" environment cannot access KVMs in the "test" environment scope.

If you want all proxies in all environments to access the same KVM, create the KVM at the organization scope.

Reference: https://docs.apigee.com/api-platform/cache/key-value-maps

Yes, all of that is true.