Skip to content

Commit f338d88

Browse files
authored
Merge pull request #197524 from adrianhall/apim/json-to-xml
json-to-xml documentation
2 parents 768fce6 + be3fff9 commit f338d88

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

articles/api-management/api-management-transformation-policies.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,65 @@ This article provides a reference for API Management policies used to transform
4545
### Policy statement
4646

4747
```xml
48-
<json-to-xml apply="always | content-type-json" consider-accept-header="true | false" parse-date="true | false"/>
48+
<json-to-xml
49+
apply="always | content-type-json"
50+
consider-accept-header="true | false"
51+
parse-date="true | false"
52+
namespace-separator="separator character"
53+
attribute-block-name="name" />
4954
```
5055

5156
### Example
5257

58+
Consider the following policy:
59+
5360
```xml
5461
<policies>
5562
<inbound>
5663
<base />
5764
</inbound>
5865
<outbound>
5966
<base />
60-
<json-to-xml apply="always" consider-accept-header="false" parse-date="false"/>
67+
<json-to-xml apply="always" consider-accept-header="false" parse-date="false" namespace-separator=":" attribute-block-name="#attrs" />
6168
</outbound>
6269
</policies>
6370
```
6471

72+
If the backend returns the following JSON:
73+
74+
``` json
75+
{
76+
"soapenv:Envelope": {
77+
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
78+
"xmlns:v1": "http://localdomain.com/core/v1",
79+
"soapenv:Header": {},
80+
"soapenv:Body": {
81+
"v1:QueryList": {
82+
"#attrs": {
83+
"queryName": "test"
84+
},
85+
"v1:QueryItem": {
86+
"name": "dummy text"
87+
}
88+
}
89+
}
90+
}
91+
}
92+
```
93+
94+
The XML response to the client will be:
95+
96+
``` xml
97+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://localdomain.com/core/v1">
98+
<soapenv:Header />
99+
<soapenv:Body>
100+
<v1:QueryList queryName="test">
101+
<name>dummy text</name>
102+
</v1:QueryList>
103+
</soapenv:Body>
104+
</soapenv:Envelope>
105+
```
106+
65107
### Elements
66108

67109
|Name|Description|Required|
@@ -75,6 +117,8 @@ This article provides a reference for API Management policies used to transform
75117
|apply|The attribute must be set to one of the following values.<br /><br /> - always - always apply conversion.<br />- content-type-json - convert only if response Content-Type header indicates presence of JSON.|Yes|N/A|
76118
|consider-accept-header|The attribute must be set to one of the following values.<br /><br /> - true - apply conversion if XML is requested in request Accept header.<br />- false -always apply conversion.|No|true|
77119
|parse-date|When set to `false` date values are simply copied during transformation|No|true|
120+
|namespace-separator|The character to use as a namespace separator|No|Underscore|
121+
|attribute-block-name|When set, properties inside the named object will be added to the element as attributes|No|Not set|
78122

79123
### Usage
80124
This policy can be used in the following policy [sections](./api-management-howto-policies.md#sections) and [scopes](./api-management-howto-policies.md#scopes).

0 commit comments

Comments
 (0)