Puppet Function: to_json

Defined in:
modules/stdlib/lib/puppet/functions/to_json.rb
Function type:
Ruby 4.x API

Overview

to_json(Any $data)Any

Examples:

how to output JSON

# output json to a file
  file { '/tmp/my.json':
    ensure  => file,
    content => to_json($myhash),
  }

Parameters:

  • data (Any)

    data structure which needs to be converted into JSON

Returns:

  • (Any)

    converted data to json



12
13
14
15
16
17
18
19
20
21
22
23
# File 'modules/stdlib/lib/puppet/functions/to_json.rb', line 12

Puppet::Functions.create_function(:to_json) do
  # @param data
  #   data structure which needs to be converted into JSON
  # @return converted data to json
  dispatch :to_json do
    param 'Any', :data
  end

  def to_json(data)
    data.to_json
  end
end