@@ -28,18 +28,23 @@ and URL-encoded data URIs. It automatically detects the encoding method and deco
2828
2929## Examples
3030
31- ### Example 1 - Decode a base64-encoded data URI
31+ ### Example 1 - Decode embedded script content
3232
33- The configuration decodes a data URI back to its original string value.
33+ Decoding a PowerShell script from a data URI is useful when receiving commands from external
34+ systems that transmit data in this format.
3435
3536``` yaml
3637# dataUriToString.example.1.dsc.config.yaml
3738$schema : https://aka.ms/dsc/schemas/v3/bundled/config/document.json
39+ parameters :
40+ encodedScript :
41+ type : string
42+ defaultValue : " data:text/plain;charset=utf8;base64,V3JpdGUtSG9zdCAnSGVsbG8sIFdvcmxkISc="
3843resources :
39- - name : Decode data URI
44+ - name : Decode and display script
4045 type : Microsoft.DSC.Debug/Echo
4146 properties :
42- output : " [dataUriToString('data:text/plain;charset=utf8;base64,SGVsbG8=' )]"
47+ output : " [dataUriToString(parameters('encodedScript') )]"
4348` ` `
4449
4550` ` ` bash
@@ -48,31 +53,34 @@ dsc config get --file dataUriToString.example.1.dsc.config.yaml
4853
4954``` yaml
5055results :
51- - name : Decode data URI
56+ - name : Decode and display script
5257 type : Microsoft.DSC.Debug/Echo
5358 result :
5459 actualState :
55- output : Hello
60+ output : Write-Host ' Hello, World!'
5661messages : []
5762hadErrors : false
5863` ` `
5964
60- ### Example 2 - Decode a data URI from parameter
65+ ### Example 2 - Extract JSON configuration from data URI
6166
62- This example shows decoding a data URI value passed through a parameter.
67+ The configuration decodes a JSON configuration that was transmitted as a data URI, then parses it
68+ using the [` json()`][06] function to access its properties.
6369
6470` ` ` yaml
6571# dataUriToString.example.2.dsc.config.yaml
6672$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
6773parameters:
68- dataFormattedString :
74+ configDataUri :
6975 type: string
70- defaultValue : " data:;base64,SGVsbG8sIFdvcmxkIQ =="
76+ defaultValue: "data:;base64,eyJzZXR0aW5nIjoidmFsdWUiLCJlbmFibGVkIjp0cnVlfQ =="
7177resources:
72- - name : Decode data URI from parameter
78+ - name: Decode and parse JSON config
7379 type: Microsoft.DSC.Debug/Echo
7480 properties:
75- output : " [dataUriToString(parameters('dataFormattedString'))]"
81+ output:
82+ rawJson: "[dataUriToString(parameters('configDataUri'))]"
83+ parsedSetting: "[json(dataUriToString(parameters('configDataUri'))).setting]"
7684` ` `
7785
7886` ` ` bash
@@ -81,28 +89,34 @@ dsc config get --file dataUriToString.example.2.dsc.config.yaml
8189
8290` ` ` yaml
8391results:
84- - name : Decode data URI from parameter
92+ - name: Decode and parse JSON config
8593 type: Microsoft.DSC.Debug/Echo
8694 result:
8795 actualState:
88- output : Hello, World!
96+ output:
97+ rawJson: '{"setting":"value","enabled":true}'
98+ parsedSetting: value
8999messages: []
90100hadErrors: false
91101` ` `
92102
93- ### Example 3 - Round-trip encoding and decoding
103+ # ## Example 3 - Process data from Azure ARM template output
94104
95- The configuration demonstrates encoding a string to a data URI and then decoding it
96- back using the [ ` dataUri ()`][02] function inside the `dataUriToString()` function .
105+ Azure ARM templates and similar systems often use data URIs for content encoding. Use
106+ ` dataUriToString ()` to decode this content back to its original form .
97107
98108` ` ` yaml
99109# dataUriToString.example.3.dsc.config.yaml
100110$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
111+ parameters:
112+ armTemplateOutput:
113+ type: string
114+ defaultValue: "data:text/plain;charset=utf8;base64,SGVsbG8sIFdvcmxkIQ=="
101115resources:
102- - name: Round-trip data URI conversion
116+ - name: Process ARM template data URI output
103117 type: Microsoft.DSC.Debug/Echo
104118 properties:
105- output: "[dataUriToString(dataUri('Configuration Data '))]"
119+ output: "[dataUriToString(parameters('armTemplateOutput '))]"
106120` ` `
107121
108122` ` ` bash
@@ -111,27 +125,34 @@ dsc config get --file dataUriToString.example.3.dsc.config.yaml
111125
112126` ` ` yaml
113127results:
114- - name: Round-trip data URI conversion
128+ - name: Process ARM template data URI output
115129 type: Microsoft.DSC.Debug/Echo
116130 result:
117131 actualState:
118- output: Configuration Data
132+ output: Hello, World!
119133messages: []
120134hadErrors: false
121135` ` `
122136
123- # ## Example 4 - Decode URL-encoded data URI
137+ # ## Example 4 - Round-trip verification
124138
125- This example demonstrates decoding a data URI that uses URL encoding instead of base64.
139+ Encoding a string to a data URI and decoding it back verifies that data survives the
140+ transformation correctly. Combine `dataUriToString()` with [`dataUri()`][02] to test this.
126141
127142` ` ` yaml
128143# dataUriToString.example.4.dsc.config.yaml
129144$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
145+ parameters:
146+ originalContent:
147+ type: string
148+ defaultValue: "Configuration with special chars: <>&\" "
130149resources:
131- - name: Decode URL-encoded data URI
150+ - name: Verify round-trip encoding
132151 type: Microsoft.DSC.Debug/Echo
133152 properties:
134- output: "[dataUriToString('data:text/plain,Hello%20World')]"
153+ output:
154+ original: "[parameters('originalContent')]"
155+ afterRoundTrip: "[dataUriToString(dataUri(parameters('originalContent')))]"
135156` ` `
136157
137158` ` ` bash
@@ -140,11 +161,13 @@ dsc config get --file dataUriToString.example.4.dsc.config.yaml
140161
141162` ` ` yaml
142163results:
143- - name: Decode URL-encoded data URI
164+ - name: Verify round-trip encoding
144165 type: Microsoft.DSC.Debug/Echo
145166 result:
146167 actualState:
147- output: Hello World
168+ output:
169+ original: 'Configuration with special chars: <>&"'
170+ afterRoundTrip: 'Configuration with special chars: <>&"'
148171messages: []
149172hadErrors: false
150173` ` `
@@ -196,3 +219,4 @@ The `dataUriToString()` function raises errors for the following conditions:
196219[03] : ./base64.md
197220[04] : ./base64ToString.md
198221[05] : ./parameters.md
222+ [06] : ./json.md
0 commit comments