Class: MultiJsonParser
- Inherits:
-
Object
- Object
- MultiJsonParser
- Defined in:
- lib/neography/multi_json_parser.rb
Class Method Summary collapse
-
.json(body) ⇒ Object
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.
Class Method Details
.json(body) ⇒ Object
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!
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/neography/multi_json_parser.rb', line 10 def self.json(body) begin MultiJson.load(body) rescue MultiJson::DecodeError, ArgumentError 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 |