Skip to content

Commit

Permalink
dealing with JSON parsing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jul 30, 2012
1 parent 4bfd6c6 commit 802802c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/neography/multi_json_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ class MultiJsonParser < HTTParty::Parser

protected

# I know this looks pretty ugly, but we have issues with Neo4j returning true, false,
# plain numbers and plain strings, which is considered by some JSON libraries to be
# invalid JSON, but some consider it perfectly fine.
# This ugly hack deals with the problem. Send me a Pull Request if you
# come up with a nicer solution... please!
#
def json
MultiJson.load(body)
begin
MultiJson.load(body)
rescue MultiJson::DecodeError
case
when body == "true"
true
when body == "false"
false
when body.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
Float(body)
else
body[1..-2]
end

end
end

end

0 comments on commit 802802c

Please sign in to comment.