summaryrefslogtreecommitdiff
path: root/code/environments/production/modules/stdlib/lib/puppet/functions/to_json.rb
blob: 782d695bd8280085512022f945f650322ff77f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Take a data structure and output it as JSON
#
# @example how to output JSON
#   # output json to a file
#     file { '/tmp/my.json':
#       ensure  => file,
#       content => to_json($myhash),
#     }
#
#
require 'json'

Puppet::Functions.create_function(:to_json) do
  dispatch :to_json do
    param 'Any', :data
  end

  def to_json(data)
    data.to_json
  end
end