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: REFERENCE.md
+70-8Lines changed: 70 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,12 +178,12 @@ in a hash.
178
178
*[`swapcase`](#swapcase): This function will swap the existing case of a string.
179
179
*[`time`](#time): This function will return the current time since epoch as an integer.
180
180
*[`to_bytes`](#to_bytes): Converts the argument into bytes, for example 4 kB becomes 4096.
181
-
*[`to_json`](#to_json): }
181
+
*[`to_json`](#to_json): Convert a data structure and output to JSON
182
182
*[`to_json_pretty`](#to_json_pretty): Convert data structure and output to pretty JSON
183
183
*[`to_python`](#to_python): Convert an object into a String containing its Python representation
184
184
*[`to_ruby`](#to_ruby): Convert an object into a String containing its Ruby representation
185
185
*[`to_toml`](#to_toml): Convert a data structure and output to TOML.
186
-
*[`to_yaml`](#to_yaml): }
186
+
*[`to_yaml`](#to_yaml): Convert a data structure and output it as YAML
187
187
*[`try_get_value`](#try_get_value)
188
188
*[`type`](#type): **DEPRECATED:** This function will cease to function on Puppet 4;
189
189
*[`type3x`](#type3x): **DEPRECATED:** This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system.
@@ -4569,19 +4569,41 @@ Returns: `Any` converted value into bytes
4569
4569
4570
4570
Type: Ruby 4.x API
4571
4571
4572
+
Convert a data structure and output to JSON
4573
+
4574
+
#### Examples
4575
+
4576
+
##### Output JSON to a file
4577
+
4578
+
```puppet
4579
+
file { '/tmp/my.json':
4580
+
ensure => file,
4581
+
content => to_json($myhash),
4572
4582
}
4583
+
```
4573
4584
4574
4585
#### `to_json(Any $data)`
4575
4586
4576
-
}
4587
+
The to_json function.
4588
+
4589
+
Returns: `String` Converted data to JSON
4577
4590
4578
-
Returns: `Any` converted data to json
4591
+
##### Examples
4592
+
4593
+
###### Output JSON to a file
4594
+
4595
+
```puppet
4596
+
file { '/tmp/my.json':
4597
+
ensure => file,
4598
+
content => to_json($myhash),
4599
+
}
4600
+
```
4579
4601
4580
4602
##### `data`
4581
4603
4582
4604
Data type: `Any`
4583
4605
4584
-
data structure which needs to be converted into JSON
4606
+
Data structure which needs to be converted into JSON
4585
4607
4586
4608
### <aname="to_json_pretty"></a>`to_json_pretty`
4587
4609
@@ -4839,25 +4861,65 @@ Data structure which needs to be converted into TOML
A hash of options that will be passed to Ruby's Psych library. Note, this could change between Puppet versions, but at time of writing these are `line_width`, `indentation`, and `canonical`.
Copy file name to clipboardExpand all lines: lib/puppet/functions/to_yaml.rb
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,29 @@
4
4
# @summary
5
5
# Convert a data structure and output it as YAML
6
6
#
7
-
# @example How to output YAML
8
-
# # output yaml to a file
9
-
# file { '/tmp/my.yaml':
10
-
# ensure => file,
11
-
# content => to_yaml($myhash),
12
-
# }
13
-
# @example Use options control the output format
7
+
# @example Output YAML to a file
14
8
# file { '/tmp/my.yaml':
15
9
# ensure => file,
16
-
# content => to_yaml($myhash, {indentation: 4})
10
+
# content => to_yaml($myhash),
11
+
# }
12
+
# @example Use options to control the output format
13
+
# file { '/tmp/my.yaml':
14
+
# ensure => file,
15
+
# content => to_yaml($myhash, {indentation => 4})
17
16
# }
18
17
Puppet::Functions.create_function(:to_yaml)do
19
18
# @param data
19
+
# The data you want to convert to YAML
20
20
# @param options
21
+
# A hash of options that will be passed to Ruby's Psych library. Note, this could change between Puppet versions, but at time of writing these are `line_width`, `indentation`, and `canonical`.
0 commit comments