Mercurial > repos > other > Puppet
diff modules/stdlib/lib/puppet/parser/functions/parsejson.rb @ 478:adf6fe9bbc17
Update Puppet modules to latest versions
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 29 Aug 2024 18:47:29 +0100 |
parents | d9352a684e62 |
children |
line wrap: on
line diff
--- a/modules/stdlib/lib/puppet/parser/functions/parsejson.rb Tue Aug 27 13:35:17 2024 +0100 +++ b/modules/stdlib/lib/puppet/parser/functions/parsejson.rb Thu Aug 29 18:47:29 2024 +0100 @@ -1,8 +1,11 @@ +# frozen_string_literal: true + +require 'puppet/util/json' # # parsejson.rb # module Puppet::Parser::Functions - newfunction(:parsejson, :type => :rvalue, :doc => <<-DOC + newfunction(:parsejson, type: :rvalue, doc: <<-DOC @summary This function accepts JSON as a string and converts it into the correct Puppet structure. @@ -12,15 +15,17 @@ > *Note:* The optional second argument can be used to pass a default value that will - be returned if the parsing of YAML string have failed. + be returned if the parsing of the JSON string failed or if the JSON parse + evaluated to nil. DOC - ) do |arguments| + ) do |arguments| raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless arguments.length >= 1 begin - PSON.load(arguments[0]) || arguments[1] + Puppet::Util::Json.load(arguments[0]) || arguments[1] rescue StandardError => e raise e unless arguments[1] + arguments[1] end end