json_mend 0.1.4 → 0.1.5
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 +4 -4
- data/.tool-versions +1 -1
- data/README.md +9 -1
- data/lib/json_mend/parser.rb +4 -4
- data/lib/json_mend/version.rb +1 -1
- data/sig/json_mend.rbs +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 07b66923caace350f973a9c1882ccd7cb4736ea1b317d9c2697eda656c47bb24
|
|
4
|
+
data.tar.gz: 1c62073a703652ad995f5ed919efb137ee4757115e8c3910a9afde15efb4d04b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ffff33143278489424877d85a2a3b08a4bf6dd8db6688dc274025ac7bbd7fe12adbbbb1cfb14ccec4c4f4bfef6133b93238a6f76388663165a79d58dbedb297
|
|
7
|
+
data.tar.gz: 83846b660a4fd41e5fe8e626366901890b27051fa9fd63a1b550ea2a49480b38b7354db8b347ef47d853f81a3d1ad9cca19e5114fc0be409507fe127d1299c09
|
data/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby 3.4.
|
|
1
|
+
ruby 3.4.8
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# JsonMend
|
|
1
|
+
# JsonMend [](https://github.com/le0pard/json_mend/actions/workflows/main.yml)
|
|
2
2
|
|
|
3
3
|
`JsonMend` is a robust Ruby gem designed to repair broken or malformed JSON strings. It is specifically optimized to handle common errors found in JSON generated by Large Language Models (LLMs), such as missing quotes, trailing commas, unescaped characters, and stray comments.
|
|
4
4
|
|
|
@@ -43,6 +43,14 @@ require 'json_mend'
|
|
|
43
43
|
broken_json = '{"name": "John", "age": 30, city: "New York"'
|
|
44
44
|
JsonMend.repair(broken_json)
|
|
45
45
|
# => '{"name":"John","age":30,"city":"New York"}'
|
|
46
|
+
|
|
47
|
+
bad_json = 'Here is the data: ```json {"id": 1} ``` check it out'
|
|
48
|
+
JsonMend.repair(bad_json)
|
|
49
|
+
# => '{"id":1}'
|
|
50
|
+
|
|
51
|
+
bad_json = '{"part": 1} {"part": 2}'
|
|
52
|
+
JsonMend.repair(bad_json)
|
|
53
|
+
# => '{"part":2}'
|
|
46
54
|
```
|
|
47
55
|
|
|
48
56
|
## Return Ruby Objects
|
data/lib/json_mend/parser.rb
CHANGED
|
@@ -173,7 +173,7 @@ module JsonMend
|
|
|
173
173
|
# Attempts to parse a single key-value pair.
|
|
174
174
|
# Returns [key, value] on success, or [nil, nil] if parsing should stop.
|
|
175
175
|
def parse_object_pair(object)
|
|
176
|
-
#
|
|
176
|
+
# Parse the Key
|
|
177
177
|
# This step includes the complex logic for merging dangling arrays.
|
|
178
178
|
pos_before_key = @scanner.pos
|
|
179
179
|
key, was_array_merged, is_bracketed = parse_object_key(object)
|
|
@@ -192,7 +192,7 @@ module JsonMend
|
|
|
192
192
|
# If we get an empty key and the next character is a closing brace, we're done.
|
|
193
193
|
return [nil, nil, false] if key.empty? && (peek_char.nil? || peek_char == '}' || @scanner.pos == pos_before_key)
|
|
194
194
|
|
|
195
|
-
#
|
|
195
|
+
# Handle Duplicate Keys (Safer Method)
|
|
196
196
|
# This is a critical repair for lists of objects missing a comma separator.
|
|
197
197
|
if object.key?(key)
|
|
198
198
|
# Instead of rewriting the string, we safely rewind the scanner to the
|
|
@@ -203,11 +203,11 @@ module JsonMend
|
|
|
203
203
|
return [nil, nil, false] # Signal to stop parsing this object.
|
|
204
204
|
end
|
|
205
205
|
|
|
206
|
-
#
|
|
206
|
+
# Parse the Separator (:)
|
|
207
207
|
skip_whitespaces
|
|
208
208
|
colon_found = @scanner.skip(/:/) # Leniently skip the colon if it exists.
|
|
209
209
|
|
|
210
|
-
#
|
|
210
|
+
# Parse the Value
|
|
211
211
|
value = parse_object_value(colon_found: colon_found || is_bracketed)
|
|
212
212
|
|
|
213
213
|
if value == :inferred_true
|
data/lib/json_mend/version.rb
CHANGED
data/sig/json_mend.rbs
CHANGED
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.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleksii Vasyliev
|
|
@@ -60,11 +60,14 @@ files:
|
|
|
60
60
|
- lib/json_mend/version.rb
|
|
61
61
|
- sig/json_mend.rbs
|
|
62
62
|
homepage: https://github.com/le0pard/json_mend
|
|
63
|
-
licenses:
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
64
65
|
metadata:
|
|
65
66
|
homepage_uri: https://github.com/le0pard/json_mend
|
|
66
67
|
source_code_uri: https://github.com/le0pard/json_mend
|
|
67
68
|
changelog_uri: https://github.com/le0pard/json_mend/releases
|
|
69
|
+
bug_tracker_uri: https://github.com/le0pard/json_mend/issues
|
|
70
|
+
documentation_uri: https://github.com/le0pard/json_mend/blob/main/README.md
|
|
68
71
|
rubygems_mfa_required: 'true'
|
|
69
72
|
rdoc_options: []
|
|
70
73
|
require_paths:
|