json_mend 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96e37cada4ab9945473f6a49b1d57a24c7822dceb0e6402847d129827686202a
4
- data.tar.gz: b497489826f674239f601203e237ee7358c7305475a2f1a43d37e465d04ce875
3
+ metadata.gz: 7aae532930afd3eabb3485f83995b7e1ee22763c4f17f1c7940af3b270f33b60
4
+ data.tar.gz: 52e364f66106063b8fec6335eff7171031cb4ac2e0f92a55cedae9d4febd205f
5
5
  SHA512:
6
- metadata.gz: 641ef79051d205ed61c16b9d6deb5f755d41bfb74f3958ac5b1910e2770ac3df2ccdf7e971ba6d44222e7a71de51078b3964da957b44bf70898db13a798ad239
7
- data.tar.gz: 605ec12dc272c8b1ce7526c8dcf53748e148a58957e6eca9ebf13133ac7f56db46a56161db03227790ddf5c064a582440a3dc02d33bb117f808e536d910f55fe
6
+ metadata.gz: 62803c4814d02e3850e23bb64fba0f31fbbfc5d6fa73b84dd2e6dee7bf670709f7c778506e64a65d0c170e26c54c239fb6f27063183199dc760e18906832630c
7
+ data.tar.gz: 7657395e2d7fed895bdc2f405ac9cb019497f7445c64e9bc3900b188124910c353d4ee3673bee90009ccc6e133d7d2aad2552971e8e1fdf12e7c3671d31d1ca7
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ # gem install benchmark-ips json-repair json_mend
4
+ # ruby -Ilib benchmark_comparison.rb
5
+ require 'benchmark/ips'
6
+ require 'json'
7
+
8
+ # --- Load Libraries ---
9
+ begin
10
+ require 'json_mend'
11
+ rescue LoadError
12
+ abort "❌ Could not load 'json_mend'. Make sure you are in the gem root or have it installed."
13
+ end
14
+
15
+ begin
16
+ require 'json/repair'
17
+ rescue LoadError
18
+ puts "❌ Could not load 'json-repair'. Benchmarks for it will be skipped."
19
+ end
20
+
21
+ puts '========================================================='
22
+ puts ' 🚀 JSON Repair Benchmark (IPS) '
23
+ puts " JsonMend (v#{JsonMend::VERSION}) vs json-repair-rb (v#{JSON::Repair::VERSION})"
24
+ puts '========================================================='
25
+ puts
26
+
27
+ # --- Test Data ---
28
+
29
+ json_object = '{"id": 1, "name": "Test", "active": true, "tags": ["a", "b"]}'
30
+
31
+ TEST_CASES = {
32
+ valid_single: {
33
+ label: 'Valid Single JSON',
34
+ input: json_object
35
+ },
36
+ concatenated: {
37
+ label: 'Concatenated JSON (x10)',
38
+ input: json_object * 10
39
+ },
40
+ simple_fix: {
41
+ label: 'Simple Fix (Missing Quotes)',
42
+ input: '{name: "Alice", age: 30, city: "Wonderland"}'
43
+ },
44
+ trailing_comma: {
45
+ label: 'Trailing Commas',
46
+ input: '{"items": [1, 2, 3,], "active": true,}'
47
+ },
48
+ comments: {
49
+ label: 'Comments (// and #)',
50
+ input: <<~JSON
51
+ {
52
+ "key": "value", // This is a comment
53
+ "config": {
54
+ "timeout": 100 # Another comment
55
+ }
56
+ }
57
+ JSON
58
+ },
59
+ complex: {
60
+ label: 'Complex & Mixed Errors',
61
+ input: <<~JSON
62
+ {
63
+ name: "Broken",
64
+ "nested": [
65
+ {id: 1,},
66
+ {id: 2}
67
+ ],
68
+ "dangling": [1, 2, 3
69
+ JSON
70
+ },
71
+ garbage: {
72
+ label: 'Heavy Garbage / Hallucinations',
73
+ input: 'Here is the JSON: ```json {"a": 1} ``` and some other text.'
74
+ },
75
+ python_style: {
76
+ label: 'Python Literals (True/None)',
77
+ input: '{"is_valid": True, "missing": None, "wrong_bool": False}'
78
+ },
79
+ single_quotes: {
80
+ label: 'Single Quotes (JS Style)',
81
+ input: "{'id': 123, 'status': 'pending', 'meta': {'active': true}}"
82
+ },
83
+ deep_nesting: {
84
+ label: 'Deeply Nested (Stack Test)',
85
+ input: "#{'{"a":' * 50}1#{'}' * 50}"
86
+ },
87
+ unbalanced: {
88
+ label: 'Truncated / Unbalanced',
89
+ input: '{"users": [{"id": 1, "name": "Alice"}, {"id": 2'
90
+ },
91
+ unescaped_control: {
92
+ label: 'Unescaped Newlines/Tabs',
93
+ input: "{\"bio\": \"This is a \n multi-line string \t with tabs.\"}"
94
+ },
95
+ large_array: {
96
+ label: 'Large Single Array (Throughput)',
97
+ input: "[#{(1..1000).map { |i| %({"id": #{i}, "val": "item_#{i}"}) }.join(',')}]"
98
+ },
99
+ concatenated_complex: {
100
+ label: 'Concatenated + Broken (LLM Stream)',
101
+ input: '{"part": 1} {part: 2, "broken": true} {"part": 3}'
102
+ }
103
+ }.freeze
104
+
105
+ # Helper to check if a library supports the input before benchmarking
106
+ def supported?(library_proc, input)
107
+ library_proc.call(input)
108
+ true
109
+ rescue StandardError
110
+ false
111
+ end
112
+
113
+ # --- Run Benchmarks ---
114
+
115
+ TEST_CASES.each_value do |data|
116
+ puts "\n\n🔸 Scenario: #{data[:label]}"
117
+ puts '-' * 40
118
+
119
+ Benchmark.ips do |x|
120
+ x.config(time: 2, warmup: 1) # Short duration for quick checks
121
+
122
+ # 1. JsonMend
123
+ if supported?(->(i) { JsonMend.repair(i) }, data[:input])
124
+ x.report('JsonMend') do
125
+ JsonMend.repair(data[:input])
126
+ end
127
+ else
128
+ puts ' JsonMend: ❌ Not Supported'
129
+ end
130
+
131
+ # 2. json-repair
132
+ if defined?(JSON::Repair)
133
+ if supported?(->(i) { JSON.repair(i) }, data[:input])
134
+ x.report('json-repair') do
135
+ JSON.repair(data[:input])
136
+ end
137
+ else
138
+ puts ' json-repair: ❌ Not Supported'
139
+ end
140
+ end
141
+
142
+ x.compare!
143
+ end
144
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonMend
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_mend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksii Vasyliev
@@ -15,28 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '0'
18
+ version: '2.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '0'
25
+ version: '2.3'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: strscan
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '3'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '3'
40
40
  description: JsonMend is a robust Ruby gem designed to repair broken or malformed
41
41
  JSON strings. It is specifically optimized to handle common errors found in JSON
42
42
  generated by Large Language Models (LLMs), such as missing quotes, trailing commas,
@@ -54,6 +54,7 @@ files:
54
54
  - LICENSE
55
55
  - README.md
56
56
  - Rakefile
57
+ - benchmark_comparison.rb
57
58
  - lib/json_mend.rb
58
59
  - lib/json_mend/parser.rb
59
60
  - lib/json_mend/version.rb