diff --git a/lib/puppet/face/facts.rb b/lib/puppet/face/facts.rb index 1075411208..3e9cdf32ec 100644 --- a/lib/puppet/face/facts.rb +++ b/lib/puppet/face/facts.rb @@ -167,7 +167,15 @@ case result when Array, Hash - Puppet::Util::Json.dump(result, :pretty => true) + # JSON < 2.8.0 would pretty print empty arrays and hashes with newlines + # Maintain that behavior for our users for now + if result.is_a?(Array) && result.empty? + "[\n\n]" + elsif result.is_a?(Hash) && result.empty? + "{\n}" + else + Puppet::Util::Json.dump(result, :pretty => true) + end else # one of VALID_TYPES above result end diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb index a7e5106a11..c3aecd0425 100644 --- a/spec/unit/application/facts_spec.rb +++ b/spec/unit/application/facts_spec.rb @@ -91,7 +91,8 @@ { "type_hash" => [{'a' => 2}, "{\n \"a\": 2\n}"], - "type_array" => [[], "[]"], + "type_empty_hash" => [{}, "{\n}"], + "type_array" => [[], "[\n\n]"], "type_string" => ["str", "str"], "type_int" => [1, "1"], "type_float" => [1.0, "1.0"],