API / APIGEE Gateway Interview Questions
How do the JSONToXML and XMLToJSON policies work in Apigee?
The JSONToXML and XMLToJSON policies enable Apigee to act as a protocol bridge between clients and backends that use different message formats. This is common in enterprise environments where legacy backends speak SOAP/XML but modern clients expect JSON REST APIs.
<!-- Client sends JSON; SOAP backend expects XML --> <!-- Step 1: Convert incoming JSON request to XML --> <JSONToXML name="JSON2XML.Request"> <Options> <RootElement>root</RootElement> <NullValue>NULL</NullValue> </Options> <OutputVariable>request</OutputVariable> <Source>request</Source> </JSONToXML> <!-- Step 2: Route to SOAP backend (via TargetEndpoint) --> <!-- Step 3: Convert XML response from SOAP backend to JSON --> <XMLToJSON name="XML2JSON.Response"> <Options> <RecognizeNull>true</RecognizeNull> <NamespaceSeparator>_</NamespaceSeparator> <TextAlwaysAsProperty>false</TextAlwaysAsProperty> </Options> <OutputVariable>response</OutputVariable> <Source>response</Source> </XMLToJSON> <!-- Flow placement: JSONToXML -> TargetEndpoint PreFlow Request (transform before backend) XMLToJSON -> TargetEndpoint PostFlow Response (transform after backend) Full bridge pattern: Client (JSON) -> [JSONToXML] -> Backend (XML/SOAP) Client (JSON) <- [XMLToJSON] <- Backend (XML/SOAP) -->
More Related questions...