json to xml Error

I got an error when trying to convert json to xml

error is :

{
	"fault": {
		"faultstring": "JSONToXML[JSON-to-XML-3]: Source response is not available",
		"detail": {
			"errorcode": "steps.json2xml.SourceUnavailable"
		}
	}
}

and this the policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML async="false" continueOnError="false" enabled="true" name="JSON-to-XML-3">
	<DisplayName>JSON to XML-3</DisplayName>
	<Properties/>
	<Options>
		<NullValue>NULL</NullValue>
		<NamespaceBlockName>#namespaces</NamespaceBlockName>
		<DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName>
		<NamespaceSeparator>:</NamespaceSeparator>
		<TextNodeName>#text</TextNodeName>
		<AttributeBlockName>#attrs</AttributeBlockName>
		<AttributePrefix>@</AttributePrefix>
		<InvalidCharsReplacement>_</InvalidCharsReplacement>
		<ObjectRootElementName>Root</ObjectRootElementName>
		<ArrayRootElementName>Array</ArrayRootElementName>
		<ArrayItemElementName>Item</ArrayItemElementName>
	</Options>
	<OutputVariable>request</OutputVariable>
	<Source>response</Source>
</JSONToXML>
Solved Solved
0 6 355
1 ACCEPTED SOLUTION

Hi @Omar Elsaid. Welcome to the Apigee community.

Based on the error encountered by you it seems that you have attached the policy at some point before the proxy receives the response from the target. Could you please share a screenshot of the trace? If not, please mention in which specific flow you have attached the above policy.

If this is indeed a case of incorrect placement of the policy then you can easily rectify it by moving your policy to the Response flow in the TargetEndpoint.

View solution in original post

6 REPLIES 6

When are you trying to execute this policy? Do you have data in your response variable?

when you hit the target, it should return the JSON data before mediation, where you can apply the JSON to XML policy to convert your response from JZON to XML usin g this policy.

its working in normal as json but when i apply the polcy its retuern erorr 
https://jsonplaceholder.typicode.com/todos/1
This is my json

Hi @Omar Elsaid. Welcome to the Apigee community.

Based on the error encountered by you it seems that you have attached the policy at some point before the proxy receives the response from the target. Could you please share a screenshot of the trace? If not, please mention in which specific flow you have attached the above policy.

If this is indeed a case of incorrect placement of the policy then you can easily rectify it by moving your policy to the Response flow in the TargetEndpoint.

thanks for your hint its working now