collectiveidea / json_spec

Easily handle JSON in RSpec and Cucumber
rubygems.org/gems/json_spec
MIT License
919 stars 114 forks source link

Can't use path accessor methods to access string representation of integer keys #24

Closed eliaslevy closed 12 years ago

eliaslevy commented 12 years ago

If you got a JSON object with string representation of integers (e.g. {"1":"foo","2":"bar"}, you can't use json_spec path accessor methods, since it will try to convert such keys to integer during path access even if the object being accessed is not an array.

Note JSON does not allow you to define integer keys in an object.

The problem lies in the path is parsed all at once at the start of path walking, which means the code does not have a change to determine whether the key is being used to access a hash or an array, and to only perform the int conversion when it is an array.

laserlemon commented 12 years ago

Great call. I'd gladly accept a pull request on this. And since I wrote json_spec, I think a new JSON path spec started to emerge. Maybe that can make its way in eventually too. I can get to the integer issue but it may be a while, so feel free to hack away.

laserlemon commented 12 years ago

Fixed in a184e7d! :metal: