Skip to content

Commit

Permalink
Allow for null/nil as a scalar JSON value
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Jun 5, 2024
1 parent 594607b commit d570893
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/whimsy/asf/json-utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ def self.cmphash(h1, h2, bc=nil, &block)
bc ||= ['root']
h1.each do |k, v1|
v2 = h2[k]
if v2.nil?
if !h2.include? k
yield [bc, 'Dropped', k, v1]
elsif v1 != v2
case v1.class.to_s
when 'String', 'Integer'
yield [bc, 'Scalar', k, [v1, v2]]
when 'Array'
yield [bc, 'Array', k, [v1, v2]]
when 'Hash'
self.cmphash v1, v2, [bc,k].flatten, &block
else
raise ArgumentError.new "#{bc.join('.')} #{k} Unexpected class #{v1.class}"
else # treat as scalar
yield [bc, 'Scalar', k, [v1, v2]]
end
end
end
Expand Down Expand Up @@ -77,4 +75,5 @@ def self.compare_json(old_json, new_json, out=$stdout)
out = StringIO.new
ASFJSON.compare_json(old_json, new_json, out=out)
puts out.string

end

0 comments on commit d570893

Please sign in to comment.