Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer loading json_pure if json has already been loaded. #21

Merged
merged 1 commit into from
Apr 1, 2016
Merged
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Unreleased Changes
------------------

* Will no longer require json_pure if the json gem has already been loaded.
This will result in a warning and a degraded experience if json < 1.8.1
has already been loaded.

Mixing json/pure with json/ext results in json errors, for example:

```ruby
some_hash = { 'jsonrpc' => 'abc', 'jsonversion' => 1 }
some_hash.to_json
#=> raises a JSON::Pure::Generator::State TypeError
```

[See related GitHub issue #20](https://github.com/jmespath/jmespath.rb/issues/20).

1.2.2 (2016-03-31)
------------------

Expand Down
23 changes: 13 additions & 10 deletions lib/jmespath.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
begin
# Attempt to load the native version if available, not availble
# by default for Ruby 1.9.3.
gem('json', '>= 1.8.1')
require 'json/ext'
rescue Gem::LoadError
# Fallback on the json_pure gem dependency.
gem('json_pure', '>= 1.8.1')
require 'json/pure'
if Object.const_defined?(:JSON) && JSON::VERSION < '1.8.1'
warn("WARNING: jmespath gem requires json gem >= 1.8.1; json #{JSON::VERSION} already loaded")
else
begin
# Attempt to load the native version if available, not availble
# by default for Ruby 1.9.3.
gem('json', '>= 1.8.1')
require 'json/ext'
rescue Gem::LoadError
# Fallback on the json_pure gem dependency.
gem('json_pure', '>= 1.8.1')
require 'json/pure'
end
end

require 'stringio'
Expand All @@ -28,7 +32,6 @@ module JMESPath

class << self


# @param [String] expression A valid
# [JMESPath](https://github.com/boto/jmespath) expression.
# @param [Hash] data
Expand Down