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! Go to Solution.
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
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
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
@Vinay Soni did you figure it out ? I got the update but do not see the comment here anymore ?
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 ?
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
thanks, i will try this.
can i also do this using AssignMessage policy?
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.
User | Count |
---|---|
7 | |
2 | |
2 | |
2 | |
1 |