Microsoft Certified: Azure Developer Associate (AZ-204)Monitor, troubleshoot, and optimize Azure solutionsHard
A developer needs to configure Azure API Management (APIM) to transform the JSON response from a backend API. The backend returns a complex JSON object, but the client application only requires a subset of the fields and needs them renamed. You need to implement an inbound policy that efficiently performs this transformation. Which policy type is best suited for this task?
- AFind and replace string policy
- BTransform XML policy
- CSet body policy with Liquid templates
- DSet header policy
Show answer & explanationAnswer & explanation
Correct answer: C. Set body policy with Liquid templates
The 'Set body' policy in APIM, especially when combined with powerful templating engines like Liquid, is ideal for complex JSON payload transformations, including selecting a subset of fields, renaming them, and restructuring the response. Liquid templates provide the flexibility to parse, manipulate, and generate JSON outputs based on the original response.
Why the other options are wrong
- A. Find and replace string policy is for simple string replacements and is not suitable for complex JSON object transformations like field selection and renaming.
- B. Transform XML policy is for XML transformations using XSLT, not for JSON.
- D. Set header policy is for modifying HTTP headers, not the message body.
APIM Set Body Policy with Liquid
The Azure API Management 'Set body' policy allows transforming the request or response body. When combined with Liquid templating, it enables powerful, custom JSON or XML manipulations.
- Used for complex JSON/XML transformations.
- Liquid templates provide conditional logic and looping.
- Can filter, rename, and restructure data fields.
Memory trick: To sculpt your JSON, set the body with Liquid's art, giving clients a fresh, new start.