I am using an AM Policy in Apigee Edge and I want to retrieve the root element “error” from the target response.content. In the current JSON path configuration the “flow.error.context” returns empty. However if i retrieve the whole content using Ref, the whole response is returned as expected. Does anyone know how to properly extract selected elements using AM Policy and JSON path?
Thank you for you replay. I had seen this solution and I did try it out and it still did not work. I tried using JSON path via EV policy which worked just fine, but I don’t want to have additional EV policy if I could configure it all within AM policy. Is this an Apigee issue and are there any other workarounds ?
here is the EV policy which works fine:
It looks like the JSON path function could only return literals, but not JSON fragments. In my case I successfully extracted “$error.status”, but I wasn’t able to extract “$.error”. It seemed like the function couldn’t handle and return JSON fragment as a string. The documentation mentions that the JSON path function returns a single element or an array, it is not thoroughly defined that only leaf elements are supported. Ref: https://docs.apigee.com/api-platform/reference/message-template-intro#json-path-function
It was my expectation that the JSON path function in AM policy behaves in the same way as the JSON path used to extract variable in an EV policy, which returns JSON fragments. In that case I would have to configure EV policy instead to retrieve the “$.error” object.
Ahhh, I understand. Good catch. You are correct that the documentation of the jsonpath function does not clearly specify that. Sorry for the confusion. I’m glad you got it working anyway.