Key Value Map, Value as JSON

Not applicable

Is there any way this would be possible? I wanted to assign for lets say a key "A" a value of {"hello":"Hello World!","barbie":"ken"}.

when i try doing that, there is an intermittent response of Malformed JSON: Expected ',' instead of '' anyone can help me ?

Solved Solved
0 8 1,423
1 ACCEPTED SOLUTION

Dear @Hanzel Garcia ,

Below Key Value Map policy works perfectly fine for me. Please let us know if it helps.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="putUrl" mapIdentifier="urlMapper">
    <Scope>apiproxy</Scope>
    <Put override="true">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
        <Value>{'hello':'Hello World!','barbie':'ken'}</Value>
    </Put>
    <Get assignTo="urlencoding.shorturl" index="1">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
    </Get>
</KeyValueMapOperations>

Cheers,

Anil Sagar

View solution in original post

8 REPLIES 8

Dear @Hanzel Garcia ,

Please post the complete policy xml to understand better. Thank you.

Cheers,

Anil Sagar

Dear @Hanzel Garcia ,

Below Key Value Map policy works perfectly fine for me. Please let us know if it helps.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="putUrl" mapIdentifier="urlMapper">
    <Scope>apiproxy</Scope>
    <Put override="true">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
        <Value>{'hello':'Hello World!','barbie':'ken'}</Value>
    </Put>
    <Get assignTo="urlencoding.shorturl" index="1">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
    </Get>
</KeyValueMapOperations>

Cheers,

Anil Sagar

Hi there, this seems to work with a little side notes perhaps, for example, 'hello' = "hello".

when using single quotation marks results on "bad string" error.

And I had used <InitialEntries></InitialEntries> tags and not that <Put></Put> tags. And maybe the <Put> tags made it to work also. Can you please differentiate the two tags for me?

Dear @Hanzel Garcia ,

Initial Entries is just like assigning default values to key store. Put is used to override existing key value store. In any case, even below map works for me.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="putUrl" mapIdentifier="urlMapper">
    <Scope>apiproxy</Scope>
    <InitialEntries>
        <Entry>
            <Key>
                <Parameter>initialJsonEntry</Parameter>
            </Key>
            <Value>{hello:'Hello World!', barbie:'ken'}</Value>
        </Entry>
    </InitialEntries>
    <Put override="true">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
        <Value>{hello:'Hello World!', barbie:'ken'}</Value>
    </Put>
    <Get assignTo="urlencoding.shorturl" index="1">
        <Key>
            <Parameter ref="urlencoding.requesturl.hashed"/>
        </Key>
    </Get>
    <Get assignTo="jsonValue" index="1">
        <Key>
            <Parameter ref="initialJsonEntry"/>
        </Key>
    </Get>
</KeyValueMapOperations>

Cheers,

Anil Sagar

Hmmm.. let me investigate a little further in this. I'll get back to you after I identify which one makes mine erroneous.

Dear @Hanzel Garcia ,

Does it work for you ? Post your policy xml here if you still see an issue.

Please keep us posted.

Cheers

Anil Sagar

Hi there, the intermittent error vanished like bubble. And since you extended and suggested a way to put KVM and I used it, I'll accept the answer :D Cheers!

🙂 Awesome, Glad issue is resolved. Keep us posted if you see any issues in future.