Puppet Function: convert_to_json_string
- Defined in:
-
lib/puppet/functions/convert_to_json_string.rb
- Function type:
- Ruby 4.x API
Overview
convert_to_json_string(Any *$args) ⇒ Any
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/puppet/functions/convert_to_json_string.rb', line 1
Puppet::Functions.create_function(:convert_to_json_string) do
def convert_to_json_string(*args)
require 'json'
value = args[0]
if (value.kind_of? Array) && value.all? {|x| x.include? ":"}
h = {}
value.each do |s|
k,v = s.split(/:/)
h[k] = v
end
return h.to_json
else
return value.to_json
end
end
end
|