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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aae532930afd3eabb3485f83995b7e1ee22763c4f17f1c7940af3b270f33b60
4
- data.tar.gz: 52e364f66106063b8fec6335eff7171031cb4ac2e0f92a55cedae9d4febd205f
3
+ metadata.gz: 07b66923caace350f973a9c1882ccd7cb4736ea1b317d9c2697eda656c47bb24
4
+ data.tar.gz: 1c62073a703652ad995f5ed919efb137ee4757115e8c3910a9afde15efb4d04b
5
5
  SHA512:
6
- metadata.gz: 62803c4814d02e3850e23bb64fba0f31fbbfc5d6fa73b84dd2e6dee7bf670709f7c778506e64a65d0c170e26c54c239fb6f27063183199dc760e18906832630c
7
- data.tar.gz: 7657395e2d7fed895bdc2f405ac9cb019497f7445c64e9bc3900b188124910c353d4ee3673bee90009ccc6e133d7d2aad2552971e8e1fdf12e7c3671d31d1ca7
6
+ metadata.gz: 4ffff33143278489424877d85a2a3b08a4bf6dd8db6688dc274025ac7bbd7fe12adbbbb1cfb14ccec4c4f4bfef6133b93238a6f76388663165a79d58dbedb297
7
+ data.tar.gz: 83846b660a4fd41e5fe8e626366901890b27051fa9fd63a1b550ea2a49480b38b7354db8b347ef47d853f81a3d1ad9cca19e5114fc0be409507fe127d1299c09
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.4.7
1
+ ruby 3.4.8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JsonMend
1
+ # JsonMend [![Ruby Checks](https://github.com/le0pard/json_mend/actions/workflows/main.yml/badge.svg)](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
@@ -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
- # --- 1. Parse the Key ---
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
- # --- 2. Handle Duplicate Keys (Safer Method) ---
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
- # --- 3. Parse the Separator (:) ---
206
+ # Parse the Separator (:)
207
207
  skip_whitespaces
208
208
  colon_found = @scanner.skip(/:/) # Leniently skip the colon if it exists.
209
209
 
210
- # --- 4. Parse the Value ---
210
+ # Parse the Value
211
211
  value = parse_object_value(colon_found: colon_found || is_bracketed)
212
212
 
213
213
  if value == :inferred_true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonMend
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
data/sig/json_mend.rbs CHANGED
@@ -1,5 +1,7 @@
1
1
  module JsonMend
2
2
  VERSION: String
3
3
 
4
+ type _JSONValue = String | Integer | Float | bool | nil | Array[_JSONValue] | Hash[String, _JSONValue]
5
+
4
6
  def self.repair: (String, ?return_objects: bool) -> String | _JSONValue | nil
5
7
  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.4
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: