to_json.rb 372 B

123456789101112131415161718192021
  1. # Take a data structure and output it as JSON
  2. #
  3. # @example how to output JSON
  4. # # output json to a file
  5. # file { '/tmp/my.json':
  6. # ensure => file,
  7. # content => to_json($myhash),
  8. # }
  9. #
  10. #
  11. require 'json'
  12. Puppet::Functions.create_function(:to_json) do
  13. dispatch :to_json do
  14. param 'Any', :data
  15. end
  16. def to_json(data)
  17. data.to_json
  18. end
  19. end