You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/logic-apps/expression-functions-reference.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4967,6 +4967,81 @@ And returns this result XML:
4967
4967
<person>
4968
4968
```
4969
4969
4970
+
*Example 4*
4971
+
4972
+
The `xml()` function expects either an object or a string containing valid XML. The function doesn't accept a raw array as input.
4973
+
4974
+
If your data is a JSON string, you can use the `json()` function to convert the string to a JSON object before you pass the result to the `xml()` function, for example:
4975
+
4976
+
```
4977
+
xml(
4978
+
json('{"root":{"array":[
4979
+
{ "ID": 1, "Name": "James" },
4980
+
{ "ID": 2, "Name": "John" },
4981
+
{ "ID": 3, "Name": "Sam" }
4982
+
]}}')
4983
+
)
4984
+
```
4985
+
4986
+
If you have a JSON array, like the following example, you have two options.
4987
+
4988
+
```json
4989
+
[
4990
+
{ "ID": 1, "Name": "James" },
4991
+
{ "ID": 2, "Name": "John" },
4992
+
{ "ID": 3, "Name": "Sam" }
4993
+
]
4994
+
```
4995
+
4996
+
Option 1: Store the JSON array in a **Compose** action named **Compose1**. Then use the `outputs()` function to return a JSON object from **Compose1**.
4997
+
4998
+
```
4999
+
{
5000
+
"root": {
5001
+
"array": @{outputs('Compose1')}
5002
+
}
5003
+
}
5004
+
```
5005
+
5006
+
Store the returned JSON object in another action named **Compose2**. You can then use the `xml()` and `outputs()` functions to create XML from the JSON object output from **Compose2**, for example:
5007
+
5008
+
```
5009
+
xml(outputs('Compose2'))
5010
+
```
5011
+
5012
+
Option 2: Store the JSON array in a **Compose** action named **Compose1**. Then use the `outputs()`, `concat()`, `json()`, and `xml()` functions to create XML from the JSON object output, for example:
5013
+
5014
+
```
5015
+
xml(
5016
+
json(
5017
+
concat(
5018
+
'{"root":{"array":',
5019
+
outputs('Compose1'),
5020
+
'}}'
5021
+
)
5022
+
)
5023
+
)
5024
+
```
5025
+
5026
+
All three examples, which include the JSON string data example, option 1, and option 2, return the following XML result:
0 commit comments