Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions spec/json-xpath_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +30,7 @@ module JSONXPath
"name" => "John",
"age" => "31",
"city" => "New York",
"zip" => ""
}

m.should eq(expected)
Expand All @@ -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|
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/node.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down