Solved Solved

Not able to extract values from json response

Not applicable

Hi,

I know there are few question related to this but it's more specific to my json response.

My json response is like below:

[{"input":"ascii","ascii":"google.com","unicode":"google.com","unicodeLabels":["google","com"],"codePoints":[["U+0067","U+006F","U+006F","U+0067","U+006C","U+0065"],["U+0063","U+006F","U+006D"]],"scripts":[["Latin","Latin","Latin","Latin","Latin","Latin"],["Latin","Latin","Latin"]],"scriptCombination":[["Latin"],["Latin"]],"success":true}]

i want to extract 'unicode' value through extract message policy.

Here's the code:

<JSONPayload>
        <Variable name="unicode">
            <JSONPath>$[0].unicode</JSONPath>
        </Variable>
    </JSONPayload>

looks like there is some problem with my extraction pattern.

Need help !!

Solved Solved
1 7 3,041
1 ACCEPTED SOLUTION
Solved Solved

sarthak
Participant V

Hi @Vinay Soni The following worked for me :

 <JSONPayload>
        <Variable name="extracted-json">
            <JSONPath>$[:1].unicode</JSONPath>
        </Variable>
    </JSONPayload>

I would also recommend to try out a jsonPath here : http://ashphy.com/JSONPathOnlineEvaluator/

Let me know if it works.

Thanks

Sarthak

View solution in original post

Solved Solved
1 0 2
7 REPLIES 7
Solved Solved

sarthak
Participant V

Hi @Vinay Soni The following worked for me :

 <JSONPayload>
        <Variable name="extracted-json">
            <JSONPath>$[:1].unicode</JSONPath>
        </Variable>
    </JSONPayload>

I would also recommend to try out a jsonPath here : http://ashphy.com/JSONPathOnlineEvaluator/

Let me know if it works.

Thanks

Sarthak

View solution in original post

Solved Solved
1 0 3

ceber
Staff

That pattern works for me. Is the content type you are trying to extract application/json? The content-type must be application/json for it to work: http://apigee.com/docs/api-services/reference/extract-variables-policy#jsonpayloadelement

1 0 2

sarthak
Participant V

@Vinay Soni did you figure it out ? I got the update but do not see the comment here anymore ?

0 4 2

Not applicable

Thanks Sarthak,

I got it working after few changes.

just one question lets say i have to modify one key/value from above Json response. Do i need to create the whole json from scratch or is there any way i can modify just 1 or 2 key/value by keeping all other values same as received ?

0 3 2

sarthak
Participant V

Ok Awesome.

You do not need to construct from scratch. You can use a javascript policy to do var val=request.body.asJSON.a; I am trying with the specific pattern now though. Will keep you posted.

You can learn more about it here : http://apigee.com/docs/api-services/reference/javascript-object-model

0 2 2

Not applicable

thanks, i will try this.

can i also do this using AssignMessage policy?

0 1 2

sarthak
Participant V

I do not think so. Javascript is probably the best bet. Using AssignMessage policy you cannot open up the json and replace some elements in it.

0 0 2
Top Labels in this Space
Top Solution Authors