Skip to content

Commit 251e1ff

Browse files
authored
Merge pull request #127765 from watana2/patch-1
Minor update - Convert JSON array to XML examples
2 parents 1a462eb + 66e9154 commit 251e1ff

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

articles/logic-apps/expression-functions-reference.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,6 +4967,81 @@ And returns this result XML:
49674967
<person>
49684968
```
49694969

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:
5027+
5028+
```xml
5029+
<root>
5030+
<array>
5031+
<ID>1</ID>
5032+
<Name>James</Name>
5033+
</array>
5034+
<array>
5035+
<ID>2</ID>
5036+
<Name>John</Name>
5037+
</array>
5038+
<array>
5039+
<ID>3</ID>
5040+
<Name>Sam</Name>
5041+
</array>
5042+
</root>
5043+
```
5044+
49705045
<a name="xpath"></a>
49715046

49725047
### xpath

0 commit comments

Comments
 (0)