Getting unexpected value trying to retrieve JSON from KVM

I'm storing and deleting array based json payload in KVM. It works fine.

But after certain time it gets distorted and looks like below

[{"CustomerEmail":"abc@bla.com"

Could you please tell what would be the issue?

Solved Solved
0 5 471
1 ACCEPTED SOLUTION

It's not clear what you mean by "distorted." You'll have to be more specific if you would like some concrete suggestions. With the information you provided, it's hard to know.

There are two possibilities.

  1. The value is not stored properly.
  2. the value is being retrieved improperly

If the problem is case #1, then the suggestion made by Isaias.arellano.delgado will be on the right track. Often when what you retrieve from the KVM does not meet your expectations, it's because you haven't LOADED the value into the KVM properly, and escaping newlines is a key aspect of that.

If the problem is case #2, I suggest you consider the commas. Does your KVM Get include an index='1' attribute like this?

<KeyValueMapOperations name='KVM1' mapIdentifier='map1'>
  <Scope>environment</Scope>
  <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
  <Get assignTo='foo' index='1'>  <!-- THIS -->
    <Key>
      <Parameter ref='variable_containing_key'/>
    </Key>
  </Get>
</KeyValueMapOperations>

If you are including that, remove it. Like this:

<KeyValueMapOperations name='KVM1' mapIdentifier='map1'>
  <Scope>environment</Scope>
  <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
  <Get assignTo='foo'>  <!-- No index -->
    <Key>
      <Parameter ref='variable_containing_key'/>
    </Key>
  </Get>
</KeyValueMapOperations>

View solution in original post

5 REPLIES 5

Make sure there are no new line characters in your JSON since KVM will split it as many values for a single key.

I tried to replace new line and make in in one line using customerInfoPayload.replace(/\n/g, " ").
But unfortunately it also gets distorted.

It's not clear what you mean by "distorted." You'll have to be more specific if you would like some concrete suggestions. With the information you provided, it's hard to know.

There are two possibilities.

  1. The value is not stored properly.
  2. the value is being retrieved improperly

If the problem is case #1, then the suggestion made by Isaias.arellano.delgado will be on the right track. Often when what you retrieve from the KVM does not meet your expectations, it's because you haven't LOADED the value into the KVM properly, and escaping newlines is a key aspect of that.

If the problem is case #2, I suggest you consider the commas. Does your KVM Get include an index='1' attribute like this?

<KeyValueMapOperations name='KVM1' mapIdentifier='map1'>
  <Scope>environment</Scope>
  <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
  <Get assignTo='foo' index='1'>  <!-- THIS -->
    <Key>
      <Parameter ref='variable_containing_key'/>
    </Key>
  </Get>
</KeyValueMapOperations>

If you are including that, remove it. Like this:

<KeyValueMapOperations name='KVM1' mapIdentifier='map1'>
  <Scope>environment</Scope>
  <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
  <Get assignTo='foo'>  <!-- No index -->
    <Key>
      <Parameter ref='variable_containing_key'/>
    </Key>
  </Get>
</KeyValueMapOperations>

Hi Dino

Thanks for the response. It works for me. Basically I was storing json payload in Apigee KVM but it changed after some time of store.

But Now I removed the index during GET operation from KVM and while storing to KVM i'm putting the json payload as one-liner.

post your policy.

For everyone reading this: In general, when asking a question, Try to err on the side of providing MORE information than you initially think might be necessary. The more context people have, the more specific information about what you are doing, the more likely someone else will be able to contribute helpful suggestions or hints.