puppet-neutron/lib/puppet/functions/convert_to_json_string.rb
Tobias Urdin 37bb654424 Use puppet4 functions-api
Change-Id: Id124ec4c598c7b6bcb7c8134d75825fd01d938d2
2018-12-18 10:32:11 +00:00

17 lines
370 B
Ruby

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