@@ -9,32 +9,31 @@ title: array
9
9
10
10
## Synopsis
11
11
12
- Creates an array from the given elements (strings, numbers, arrays , or objects) .
12
+ Wraps a single value (string, number, array , or object) in an array .
13
13
14
14
## Syntax
15
15
16
16
``` Syntax
17
- array(<element1>, <element2>, ... )
17
+ array(<value> )
18
18
```
19
19
20
20
## Description
21
21
22
- The ` array() ` function creates an array from the provided arguments, allowing
23
- mixed data types within the same array. Unlike ` createArray() ` which requires
24
- all elements to be the same type, ` array() ` accepts any combination of strings,
25
- numbers, arrays, and objects as arguments.
22
+ The ` array() ` function returns a new array containing the single input value.
23
+ The value can be a string, number, array, or object. Use
24
+ ` createArray() ` to construct arrays with multiple elements of the same type.
26
25
27
- This function is useful when you need to combine different types of data into a
28
- single collection, such as mixing configuration values, computed results, and
29
- structured metadata in deployment scenarios .
26
+ This function is useful when a schema expects an array, but you only have a
27
+ single value, or when you need to nest an existing array or object inside an
28
+ outer array .
30
29
31
30
## Examples
32
31
33
- ### Example 1 - Build a deployment plan
32
+ ### Example 1 - Wrap an existing array as a single element
34
33
35
- This example demonstrates combining different data types to create a comprehensive
36
- deployment configuration. The array contains an existing server list, a numeric
37
- batch size, and a configuration object with deployment strategy details .
34
+ This example demonstrates wrapping an existing server list into a single array
35
+ element, producing a nested array. This can be useful when a downstream schema
36
+ expects an array of arrays .
38
37
39
38
``` yaml
40
39
# array.example.1.dsc.config.yaml
@@ -52,7 +51,7 @@ resources:
52
51
- name : Deployment Plan
53
52
type : Microsoft.DSC.Debug/Echo
54
53
properties :
55
- output : " [array(parameters('webServers'), parameters('batchSize'), createObject('strategy', 'blue-green') )]"
54
+ output : " [array(parameters('webServers'))]"
56
55
` ` `
57
56
58
57
` ` ` bash
@@ -68,17 +67,14 @@ results:
68
67
output :
69
68
- - web01
70
69
- web02
71
- - 2
72
- - strategy : blue-green
73
70
messages : []
74
71
hadErrors : false
75
72
` ` `
76
73
77
- ### Example 2 - Compose mixed telemetry payload parts
74
+ ### Example 2 - Wrap a single object for payloads
78
75
79
- This example shows how to construct a telemetry payload by combining a string
80
- identifier, structured metadata object, and numeric status code into a single
81
- array for logging or monitoring systems.
76
+ This example shows how to wrap a structured metadata object into an array for
77
+ logging or monitoring systems that expect arrays.
82
78
83
79
` ` ` yaml
84
80
# array.example.2.dsc.config.yaml
@@ -92,7 +88,7 @@ resources:
92
88
type : Microsoft.DSC.Debug/Echo
93
89
properties :
94
90
output :
95
- payload : " [array(parameters('correlationId'), createObject('severity', 'info'), 200 )]"
91
+ payload : " [array(createObject('severity', 'info'))]"
96
92
` ` `
97
93
98
94
` ` ` bash
@@ -107,18 +103,15 @@ results:
107
103
actualState :
108
104
output :
109
105
payload :
110
- - ABC123
111
106
- severity : info
112
- - 200
113
107
messages : []
114
108
hadErrors : false
115
109
` ` `
116
110
117
- ### Example 3 - Combine generated and literal collections
111
+ ### Example 3 - Wrap generated collections
118
112
119
- This example demonstrates nesting arrays and objects within a parent array,
120
- showing how ` array()` can combine results from other DSC functions like
121
- ` createArray()` and `createObject()` with literal values.
113
+ This example demonstrates wrapping a generated collection (like one from
114
+ ` createArray()` or `createObject()`) into an outer array.
122
115
123
116
` ` ` yaml
124
117
# array.example.3.dsc.config.yaml
@@ -128,7 +121,8 @@ resources:
128
121
type: Microsoft.DSC.Debug/Echo
129
122
properties:
130
123
output:
131
- combined: "[array(createArray('a','b'), array(1,2), createObject('k','v'))]"
124
+ combinedArray: "[array(createArray('a','b'))]"
125
+ combinedObject: "[array(createObject('k','v'))]"
132
126
` ` `
133
127
134
128
` ` ` bash
@@ -142,31 +136,31 @@ results:
142
136
result:
143
137
actualState:
144
138
output:
145
- combined :
139
+ combinedArray :
146
140
- - a
147
141
- b
148
- - - 1
149
- - 2
142
+ combinedObject:
150
143
- k: v
151
144
messages: []
152
145
hadErrors: false
153
146
` ` `
154
147
155
148
# # Parameters
156
149
157
- # ## element1, element2, ...
150
+ # ## value
158
151
159
- The elements to include in the array.
152
+ The single value to wrap in the array.
160
153
161
154
` ` ` yaml
162
155
Type: string, number, array, or object
163
156
Required: false
164
- Multiplicity: 0 or more
157
+ MinimumCount: 1
158
+ MaximumCount: 1
165
159
` ` `
166
160
167
- Each element provided as an argument will be added to the resulting array in the
168
- order specified. All elements must be one of the four accepted types : string,
169
- number (integer), array, or object. Boolean and null values are not supported.
161
+ The provided value will be wrapped into the resulting array. The value must be
162
+ one of the four accepted types : string, number (integer), array, or object.
163
+ Boolean and null values are not supported.
170
164
171
165
# # Output
172
166
0 commit comments