File: to_json.rb

package info (click to toggle)
puppet-module-puppetlabs-stdlib 9.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,448 kB
  • sloc: ruby: 3,522; sh: 46; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 531 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

require 'json'
# @summary
#   Convert a data structure and output to JSON
Puppet::Functions.create_function(:'stdlib::to_json') do
  # @param data
  #   Data structure which needs to be converted into JSON
  #
  # @example Output JSON to a file
  #   file { '/tmp/my.json':
  #     ensure  => file,
  #     content => stdlib::to_json($myhash),
  #   }
  #
  # @return [String] Converted data to JSON
  dispatch :to_json do
    param 'Any', :data
  end

  def to_json(data)
    data.to_json
  end
end