json-endure 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,8 @@ an array value, hash key, or hash value. These methods may be helpful
8
8
  in a case where you want to examine the first bunch of bytes of a very
9
9
  large file, without downloading all of it.
10
10
 
11
- It will not repair bad JSON encountered before the truncation.
11
+ It will not repair bad JSON encountered before the truncation. All
12
+ JSON-restoration code has been implemented in Ruby.
12
13
 
13
14
  License
14
15
  -------
@@ -22,16 +23,17 @@ License-file referencing and other doc. formatting taken from
22
23
  Install
23
24
  -------
24
25
 
25
- > gem install json-endure
26
+ gem install json-endure
26
27
 
27
28
  Usage
28
29
  -----
29
-
30
- >> require 'json-endure' #=> true
31
- >> broken = String.new('{ "123": "90", "abc": { "30') #=> "{ \"123\": \"90\", \"abc\": { \"30"
32
- >> good_hash = JSON.endure_and_parse broken #=> {"123"=>"90", "abc"=>{"30"=>""}}
33
- >> fixed = broken.coax_into_json! #=> "{ \"123\": \"90\", \"abc\": { \"30\":\"\"}}"
34
- >> broken #=> "{ \"123\": \"90\", \"abc\": { \"30\":\"\"}}"
30
+ ```ruby
31
+ require 'json-endure' #=> true
32
+ broken = String.new('{ "123": "90", "abc": { "30') #=> "{ \"123\": \"90\", \"abc\": { \"30"
33
+ good_hash = JSON.endure_and_parse broken #=> {"123"=>"90", "abc"=>{"30"=>""}}
34
+ fixed = broken.coax_into_json! #=> "{ \"123\": \"90\", \"abc\": { \"30\":\"\"}}"
35
+ broken #=> "{ \"123\": \"90\", \"abc\": { \"30\":\"\"}}"
36
+ ```
35
37
 
36
38
  Contribute
37
39
  ----------
data/json-endure.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = 'json-endure'
4
- s.version = '0.2.2'
4
+ s.version = '0.2.3'
5
5
  s.summary = %q{Handle truncated JSON-text}
6
6
 
7
7
  s.description = %q{Helper methods to JSON and String to make-do } +
@@ -118,7 +118,11 @@ module JSON
118
118
  end
119
119
 
120
120
  when JsonStateVariable::IN_HASH_IN_VALUE
121
- state_stack.last = JsonStateVariable::IN_HASH_PRE_KEY if c == ','
121
+ if c == ','
122
+ state_stack.last = JsonStateVariable::IN_HASH_PRE_KEY
123
+ elsif c == '}'
124
+ state_stack.pop
125
+ end
122
126
 
123
127
  when JsonStateVariable::IN_HASH_IN_STR_VALUE
124
128
  if c == '\\'
data/spec/json_spec.rb CHANGED
@@ -12,6 +12,16 @@ describe JSON, "::endure" do
12
12
 
13
13
  test_value.should eq(expected_value)
14
14
  end
15
+
16
+ it "handles strings with embedded hashes" do
17
+ string = String.new('{"123":{"90":"abc"},"30":40}')
18
+ expected_value = String.new('{"123":{"90":"abc"},"30":40}')
19
+
20
+ test_value = JSON.endure(string)
21
+
22
+ test_value.should eq(expected_value)
23
+ end
24
+
15
25
  end
16
26
 
17
27
  describe JSON, "::endure_and_parse" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-endure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-11 00:00:00.000000000Z
12
+ date: 2012-09-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2168697580 !ruby/object:Gem::Requirement
16
+ requirement: &2153549280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2168697580
24
+ version_requirements: *2153549280
25
25
  description: Helper methods to JSON and String to make-do with truncated JSON text.
26
26
  email: Andrew_Burnheimer@cable.comcast.com
27
27
  executables: []