Is it possible to store JSON objects in the KVM?

Not applicable

Hi,

I am attempting to store the following example in the KVM. As you can see, the value is a JSON object.

{
  "entry": [
    { 
        "name": "kid1", 
        "value": {
            "components": {
                "n": "test1",
                "e": "test2"            
            }
        }
    },
    { 
        "name": "kid2", 
        "value": {
            "components": {
                "n": "test3",
                "e": "test4"  
            }
        }
    }
  ],
  "name": "test_kvm"
}

However, when I try and POST this in Postman, I get the following error.

{
  "message": "Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@6d839557; line: 4, column: 23] (through reference chain: com.apigee.keyvaluemap.resource.KeyValueMap[\"entry\"]->com.apigee.keyvaluemap.resource.KeyValueMapEntry[\"value\"])",
  "contexts": []
}

Does anyone know whether what I am doing wrong? Or whether it's possible to store JSON objects in the KVM?

FYI, in regards to JSON settings, I have set the body to "raw" and type to JSON(application/json).

Thanks,

Marlene

Solved Solved
0 6 2,763
1 ACCEPTED SOLUTION

Hi @marlene.pecotich,

You have to escape your JSON like below:

{  
 "name" : "Map_name",
 "entry" : [ 
  {
   "name" : "Key1",
    "value" : "{ \"name\": \"John\", \"work\" : \"Engineering\"}"
  } 
 ]
}

Also if your org supports CPS then you can directly create KVM with JSON using CPS management APIS as they support XML payload where you can use JSON string directly.

Payload for CPS:

<Entry name="Env_Key1">{ "name" : "John", "work": "Engineering"}</Entry>

Details of CPS Management APIs can be found at CPS Create KVM in environment.

Hope this helps

View solution in original post

6 REPLIES 6

Not applicable

Hello @marlene.pecotich,

Please make a single line JSON object and then insert. Like:

"{"entry":[{"name":"kid1","value":{"components":{"n":"test1","e":"test2"}}},{"name":"kid2","value":{"components":{"n":"test3","e":"test4"}}}],"name": "test_kvm"}".

I tried from the UI and it works for me.

Hi @marlene.pecotich,

You have to escape your JSON like below:

{  
 "name" : "Map_name",
 "entry" : [ 
  {
   "name" : "Key1",
    "value" : "{ \"name\": \"John\", \"work\" : \"Engineering\"}"
  } 
 ]
}

Also if your org supports CPS then you can directly create KVM with JSON using CPS management APIS as they support XML payload where you can use JSON string directly.

Payload for CPS:

<Entry name="Env_Key1">{ "name" : "John", "work": "Engineering"}</Entry>

Details of CPS Management APIs can be found at CPS Create KVM in environment.

Hope this helps

Since this is storing it as a JSON string do you have to convert it to a json object when you retrieve the value?

If it is stored as json, you must perform JSON.parse() on the retrieved value.

Old question, I know.

Hi,

Just want to add small point regarding KVM. If we want to use any value which is having "," we should not use index attribute. If we remove then it will work. Even JSON object also works.

Thanks,

G Ramya

Thank you @ramyagullapalli  this helped a lot