Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / functions / to_json.rb
1 require 'json'
2 # @summary
3 #   Convert a data structure and output to JSON
4 #
5 # @example how to output JSON
6 #   # output json to a file
7 #     file { '/tmp/my.json':
8 #       ensure  => file,
9 #       content => to_json($myhash),
10 #     }
11 #
12 Puppet::Functions.create_function(:to_json) do
13   # @param data
14   #   data structure which needs to be converted into JSON
15   # @return converted data to json
16   dispatch :to_json do
17     param 'Any', :data
18   end
19
20   def to_json(data)
21     data.to_json
22   end
23 end