Skip to content

Commit a4e3d2e

Browse files
authored
Merge pull request #207555 from yoelhor/patch-298
[Azure AD B2C] Generate JSON collections
2 parents 8c8bc79 + 2d8b449 commit a4e3d2e

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

articles/active-directory-b2c/json-transformations.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ manager: CelesteDG
99
ms.service: active-directory
1010
ms.workload: identity
1111
ms.topic: reference
12-
ms.date: 02/16/2022
12+
ms.date: 08/10/2022
1313
ms.author: kengaderdus
1414
ms.subservice: B2C
1515
---
@@ -59,6 +59,90 @@ Check out the [Live demo](https://github.com/azure-ad-b2c/unit-tests/tree/main/c
5959
| InputParameter | Any string following dot notation | string | The JsonPath of the JSON where the constant string value will be inserted into. |
6060
| OutputClaim | outputClaim | string | The generated JSON string. |
6161

62+
### JSON Arrays
63+
64+
To add JSON objects to a JSON array, use the format of **array name** and the **index** in the array. The array is zero based. Start with zero to N, without skipping any number. The items in the array can contain any object. For example, the first item contains two objects, *app* and *appId*. The second item contains a single object, *program*. The third item contains four objects, *color*, *language*, *logo* and *background*.
65+
66+
The following example demonstrates how to configure JSON arrays. The **emails** array uses the `InputClaims` with dynamic values. The **values** array uses the `InputParameters` with static values.
67+
68+
```xml
69+
<ClaimsTransformation Id="GenerateJsonPayload" TransformationMethod="GenerateJson">
70+
<InputClaims>
71+
<InputClaim ClaimTypeReferenceId="mailToName1" TransformationClaimType="emails.0.name" />
72+
<InputClaim ClaimTypeReferenceId="mailToAddress1" TransformationClaimType="emails.0.address" />
73+
<InputClaim ClaimTypeReferenceId="mailToName2" TransformationClaimType="emails.1.name" />
74+
<InputClaim ClaimTypeReferenceId="mailToAddress2" TransformationClaimType="emails.1.address" />
75+
</InputClaims>
76+
<InputParameters>
77+
<InputParameter Id="values.0.app" DataType="string" Value="Mobile app" />
78+
<InputParameter Id="values.0.appId" DataType="string" Value="123" />
79+
<InputParameter Id="values.1.program" DataType="string" Value="Holidays" />
80+
<InputParameter Id="values.2.color" DataType="string" Value="Yellow" />
81+
<InputParameter Id="values.2.language" DataType="string" Value="Spanish" />
82+
<InputParameter Id="values.2.logo" DataType="string" Value="contoso.png" />
83+
<InputParameter Id="values.2.background" DataType="string" Value="White" />
84+
</InputParameters>
85+
<OutputClaims>
86+
<OutputClaim ClaimTypeReferenceId="result" TransformationClaimType="outputClaim" />
87+
</OutputClaims>
88+
</ClaimsTransformation>
89+
```
90+
91+
The result of this claims transformation:
92+
93+
```json
94+
{
95+
"values": [
96+
{
97+
"app": "Mobile app",
98+
"appId": "123"
99+
},
100+
{
101+
"program": "Holidays"
102+
},
103+
{
104+
"color": "Yellow",
105+
"language": "Spanish",
106+
"logo": "contoso.png",
107+
"background": "White"
108+
}
109+
],
110+
"emails": [
111+
{
112+
"name": "Joni",
113+
"address": "[email protected]"
114+
},
115+
{
116+
"name": "Emily",
117+
"address": "[email protected]"
118+
}
119+
]
120+
}
121+
```
122+
123+
To specify a JSON array in both the input claims and the input parameters, you must start the array in the `InputClaims` element, zero to N. Then, in the `InputParameters` element continue the index from the last index.
124+
125+
The following example demonstrates an array that is defined in both the input claims and the input parameters. The first item of the *values* array `values.0` is defined in the input claims. The input parameters continue from index one `values.1` through two index `values.2`.
126+
127+
```xml
128+
<ClaimsTransformation Id="GenerateJsonPayload" TransformationMethod="GenerateJson">
129+
<InputClaims>
130+
<InputClaim ClaimTypeReferenceId="app" TransformationClaimType="values.0.app" />
131+
<InputClaim ClaimTypeReferenceId="appId" TransformationClaimType="values.0.appId" />
132+
</InputClaims>
133+
<InputParameters>
134+
<InputParameter Id="values.1.program" DataType="string" Value="Holidays" />
135+
<InputParameter Id="values.2.color" DataType="string" Value="Yellow" />
136+
<InputParameter Id="values.2.language" DataType="string" Value="Spanish" />
137+
<InputParameter Id="values.2.logo" DataType="string" Value="contoso.png" />
138+
<InputParameter Id="values.2.background" DataType="string" Value="White" />
139+
</InputParameters>
140+
<OutputClaims>
141+
<OutputClaim ClaimTypeReferenceId="result" TransformationClaimType="outputClaim" />
142+
</OutputClaims>
143+
</ClaimsTransformation>
144+
```
145+
62146
### Example of GenerateJson
63147

64148
The following example generates a JSON string based on the claim value of "email" and "OTP" and constant strings.

0 commit comments

Comments
 (0)