diff --git a/spec/json-xpath_spec.cr b/spec/json-xpath_spec.cr index 052d633..30976af 100644 --- a/spec/json-xpath_spec.cr +++ b/spec/json-xpath_spec.cr @@ -17,7 +17,8 @@ module JSONXPath s = %({ "name":"John", "age":31, - "city":"New York" + "city":"New York", + "zip": null }) doc = Node.parse(s) m = Hash(String, String).new @@ -29,6 +30,7 @@ module JSONXPath "name" => "John", "age" => "31", "city" => "New York", + "zip" => "" } m.should eq(expected) @@ -38,11 +40,12 @@ module JSONXPath s = %([ { "name":"Ford", "models":[ "Fiesta", "Focus", "Mustang" ] }, { "name":"BMW", "models":[ "320", "X3", "X5" ] }, - { "name":"Fiat", "models":[ "500", "Panda" ] } + { "name":"Fiat", "models":[ "500", "Panda" ] }, + null ]) doc = Node.parse(s) - doc.children.size.should eq(3) + doc.children.size.should eq(4) m = Hash(String, Array(String)).new doc.children.each do |n| @@ -62,7 +65,8 @@ module JSONXPath expected = {"Ford" => ["Fiesta", "Focus", "Mustang"], "BMW" => ["320", "X3", "X5"], - "Fiat" => ["500", "Panda"]} + "Fiat" => ["500", "Panda"], + "" => [] of String} m.should eq(expected) end diff --git a/src/node.cr b/src/node.cr index 1da7360..7ae5526 100644 --- a/src/node.cr +++ b/src/node.cr @@ -53,7 +53,7 @@ module JSONXPath when String n = Node.new(NodeType::Text, level, json.as_s, json) add_node(n, node) - when Float, Bool, Int + when Float, Bool, Int, Nil n = Node.new(NodeType::Text, level, json.to_s, json) add_node(n, node) else