json 2.12.2 → 2.15.0

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: b76bc749fd1bc82cd84df8c7d14317305d5426e0962d0e034864b218e952e474
4
- data.tar.gz: 8e8d9179b6ca7ce69c7a281691973dc9cb1e6b147a5812b96d02c3b41d8f8cec
3
+ metadata.gz: ff78e67c786dd7f165bdd12e945ad6cb9de9c15c491b7423a6a7b9cc176c4c56
4
+ data.tar.gz: '068efe1a1652768b10fb4da5c0fe8e0d4296147efcf0a75a02ca667e66bb60f7'
5
5
  SHA512:
6
- metadata.gz: a241873428f8de2106604f3a31484aa243b6f62c6c6f38f8e381669f937b19f03b35add48ddf4f1d24c5a9f469c2dbdc8bafca36d8f3bcf678313ad8d9ea11d3
7
- data.tar.gz: 99d07dbf3dcacda3cf662ee05bc181aa3ca6e43ce8779b9f5edc454fba8e718abe876eb81b4918e0c0bb1a3b4286e1d85df086425e552743420942a8e0098f0e
6
+ metadata.gz: f326bc37bf1a00e3c379bbdf66591b3cd37a1b768f7432fcafe771eeede97b50a45151012d1e946c0c72038c7dc34cd0a935a685a9211a64699de235334d0a1a
7
+ data.tar.gz: ea2a1bfb35384feb19f9c16764490bbd57a772bbf2bfe44c206a3bc6f45e86d452cecb30830900e0f0e12e9ece5b9fa18aba25b2bee221b4982f805ec0df32a0
data/CHANGES.md CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2025-09-22 (2.15.0)
6
+
7
+ * `JSON::Coder` callback now receive a second argument to convey whether the object is a hash key.
8
+ * Tuned the floating point number generator to not use scientific notation as agressively.
9
+
10
+ ### 2025-09-18 (2.14.1)
11
+
12
+ * Fix `IndexOutOfBoundsException` in the JRuby extension when encoding shared strings.
13
+
14
+ ### 2025-09-18 (2.14.0)
15
+
16
+ * Add new `allow_duplicate_key` generator options. By default a warning is now emitted when a duplicated key is encountered.
17
+ In `json 3.0` an error will be raised.
18
+ ```ruby
19
+ >> Warning[:deprecated] = true
20
+ >> puts JSON.generate({ foo: 1, "foo" => 2 })
21
+ (irb):2: warning: detected duplicate key "foo" in {foo: 1, "foo" => 2}.
22
+ This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
23
+ {"foo":1,"foo":2}
24
+ >> JSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: false)
25
+ detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
26
+ ```
27
+ * Fix `JSON.generate` `strict: true` mode to also restrict hash keys.
28
+ * Fix `JSON::Coder` to also invoke block for hash keys that aren't strings nor symbols.
29
+ * Fix `JSON.unsafe_load` usage with proc
30
+ * Fix the parser to more consistently reject invalid UTF-16 surogate pairs.
31
+ * Stop defining `String.json_create`, `String#to_json_raw`, `String#to_json_raw_object` when `json/add` isn't loaded.
32
+
33
+ ### 2025-07-28 (2.13.2)
34
+
35
+ * Improve duplicate key warning and errors to include the key name and point to the right caller.
36
+
37
+ ### 2025-07-24 (2.13.1)
38
+
39
+ * Fix support for older compilers without `__builtin_cpu_supports`.
40
+
41
+ ### 2025-07-17 (2.13.0)
42
+
43
+ * Add new `allow_duplicate_key` parsing options. By default a warning is now emitted when a duplicated key is encountered.
44
+ In `json 3.0` an error will be raised.
45
+ * Optimize parsing further using SIMD to scan strings.
46
+
5
47
  ### 2025-05-23 (2.12.2)
6
48
 
7
49
  * Fix compiler optimization level.
@@ -30,7 +72,7 @@
30
72
  ### 2025-04-24 (2.11.1)
31
73
 
32
74
  * Add back `JSON.restore`, `JSON.unparse`, `JSON.fast_unparse` and `JSON.pretty_unparse`.
33
- These were deprecated 16 years ago, but never emited warnings, only undocumented, so are
75
+ These were deprecated 16 years ago, but never emitted warnings, only undocumented, so are
34
76
  still used by a few gems.
35
77
 
36
78
  ### 2025-04-24 (2.11.0)
@@ -57,7 +99,7 @@
57
99
  ### 2025-03-12 (2.10.2)
58
100
 
59
101
  * Fix a potential crash in the C extension parser.
60
- * Raise a ParserError on all incomplete unicode escape sequence. This was the behavior until `2.10.0` unadvertently changed it.
102
+ * Raise a ParserError on all incomplete unicode escape sequence. This was the behavior until `2.10.0` inadvertently changed it.
61
103
  * Ensure document snippets that are included in parser errors don't include truncated multibyte characters.
62
104
  * Ensure parser error snippets are valid UTF-8.
63
105
  * Fix `JSON::GeneratorError#detailed_message` on Ruby < 3.2
@@ -88,7 +130,7 @@
88
130
 
89
131
  ### 2024-11-14 (2.8.2)
90
132
 
91
- * `JSON.load_file` explictly read the file as UTF-8.
133
+ * `JSON.load_file` explicitly read the file as UTF-8.
92
134
 
93
135
  ### 2024-11-06 (2.8.1)
94
136
 
@@ -96,7 +138,7 @@
96
138
 
97
139
  ### 2024-11-06 (2.8.0)
98
140
 
99
- * Emit a deprecation warning when `JSON.load` create custom types without the `create_additions` option being explictly enabled.
141
+ * Emit a deprecation warning when `JSON.load` create custom types without the `create_additions` option being explicitly enabled.
100
142
  * Prefer to use `JSON.unsafe_load(string)` or `JSON.load(string, create_additions: true)`.
101
143
  * Emit a deprecation warning when serializing valid UTF-8 strings encoded in `ASCII_8BIT` aka `BINARY`.
102
144
  * Bump required Ruby version to 2.7.
@@ -104,7 +146,7 @@
104
146
  pre-existing support for comments, make it suitable to parse `jsonc` documents.
105
147
  * Many performance improvements to `JSON.parse` and `JSON.load`, up to `1.7x` faster on real world documents.
106
148
  * Some minor performance improvements to `JSON.dump` and `JSON.generate`.
107
- * `JSON.pretty_generate` no longer include newline inside empty object and arrays.
149
+ * `JSON.pretty_generate` no longer includes newlines inside empty object and arrays.
108
150
 
109
151
  ### 2024-11-04 (2.7.6)
110
152
 
@@ -121,13 +163,13 @@
121
163
  * Workaround a bug in 3.4.8 and older https://github.com/rubygems/rubygems/pull/6490.
122
164
  This bug would cause some gems with native extension to fail during compilation.
123
165
  * Workaround different versions of `json` and `json_pure` being loaded (not officially supported).
124
- * Make `json_pure` Ractor compatible.
166
+ * Make `json_pure` Ractor compatible.
125
167
 
126
168
  ### 2024-10-24 (2.7.3)
127
169
 
128
170
  * Numerous performance optimizations in `JSON.generate` and `JSON.dump` (up to 2 times faster).
129
- * Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
130
- * Fix json-pure's `Object#to_json` to accept non state arguments
171
+ * Limit the size of ParserError exception messages, only include up to 32 bytes of the unparsable source.
172
+ * Fix json-pure's `Object#to_json` to accept non-state arguments.
131
173
  * Fix multiline comment support in `json-pure`.
132
174
  * Fix `JSON.parse` to no longer mutate the argument encoding when passed an ASCII-8BIT string.
133
175
  * Fix `String#to_json` to raise on invalid encoding in `json-pure`.
@@ -272,6 +314,7 @@
272
314
  ## 2015-09-11 (2.0.0)
273
315
  * Now complies to newest JSON RFC 7159.
274
316
  * Implements compatibility to ruby 2.4 integer unification.
317
+ * Removed support for `quirks_mode` option.
275
318
  * Drops support for old rubies whose life has ended, that is rubies < 2.0.
276
319
  Also see https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/
277
320
  * There were still some mentions of dual GPL licensing in the source, but JSON
data/README.md CHANGED
@@ -97,7 +97,7 @@ Instead it is recommended to use the newer `JSON::Coder` API:
97
97
 
98
98
  ```ruby
99
99
  module MyApp
100
- API_JSON_CODER = JSON::Coder.new do |object|
100
+ API_JSON_CODER = JSON::Coder.new do |object, is_object_key|
101
101
  case object
102
102
  when Time
103
103
  object.iso8601(3)
@@ -113,6 +113,8 @@ puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
113
113
  The provided block is called for all objects that don't have a native JSON equivalent, and
114
114
  must return a Ruby object that has a native JSON equivalent.
115
115
 
116
+ It is also called for objects that do have a JSON equivalent, but are used as Hash keys, for instance `{ 1 => 2}`.
117
+
116
118
  ## Combining JSON fragments
117
119
 
118
120
  To combine JSON fragments into a bigger JSON document, you can use `JSON::Fragment`:
@@ -24,6 +24,14 @@ typedef unsigned char _Bool;
24
24
  #endif
25
25
  #endif
26
26
 
27
+ #ifndef NOINLINE
28
+ #if defined(__has_attribute) && __has_attribute(noinline)
29
+ #define NOINLINE() __attribute__((noinline))
30
+ #else
31
+ #define NOINLINE()
32
+ #endif
33
+ #endif
34
+
27
35
  #ifndef RB_UNLIKELY
28
36
  #define RB_UNLIKELY(expr) expr
29
37
  #endif
@@ -169,12 +177,17 @@ static inline void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
169
177
  }
170
178
  }
171
179
 
172
- static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len)
180
+ static inline void fbuffer_append_reserved(FBuffer *fb, const char *newstr, unsigned long len)
181
+ {
182
+ MEMCPY(fb->ptr + fb->len, newstr, char, len);
183
+ fbuffer_consumed(fb, len);
184
+ }
185
+
186
+ static inline void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len)
173
187
  {
174
188
  if (len > 0) {
175
189
  fbuffer_inc_capa(fb, len);
176
- MEMCPY(fb->ptr + fb->len, newstr, char, len);
177
- fbuffer_consumed(fb, len);
190
+ fbuffer_append_reserved(fb, newstr, len);
178
191
  }
179
192
  }
180
193
 
@@ -197,11 +210,24 @@ static void fbuffer_append_str(FBuffer *fb, VALUE str)
197
210
  const char *newstr = StringValuePtr(str);
198
211
  unsigned long len = RSTRING_LEN(str);
199
212
 
200
- RB_GC_GUARD(str);
201
-
202
213
  fbuffer_append(fb, newstr, len);
203
214
  }
204
215
 
216
+ static void fbuffer_append_str_repeat(FBuffer *fb, VALUE str, size_t repeat)
217
+ {
218
+ const char *newstr = StringValuePtr(str);
219
+ unsigned long len = RSTRING_LEN(str);
220
+
221
+ fbuffer_inc_capa(fb, repeat * len);
222
+ while (repeat) {
223
+ #ifdef JSON_DEBUG
224
+ fb->requested = len;
225
+ #endif
226
+ fbuffer_append_reserved(fb, newstr, len);
227
+ repeat--;
228
+ }
229
+ }
230
+
205
231
  static inline void fbuffer_append_char(FBuffer *fb, char newchr)
206
232
  {
207
233
  fbuffer_inc_capa(fb, 1);
@@ -9,31 +9,7 @@ else
9
9
  $defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
10
10
 
11
11
  if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
12
- if RbConfig::CONFIG['host_cpu'] =~ /^(arm.*|aarch64.*)/
13
- # Try to compile a small program using NEON instructions
14
- if have_header('arm_neon.h')
15
- have_type('uint8x16_t', headers=['arm_neon.h']) && try_compile(<<~'SRC')
16
- #include <arm_neon.h>
17
- int main() {
18
- uint8x16_t test = vdupq_n_u8(32);
19
- return 0;
20
- }
21
- SRC
22
- $defs.push("-DJSON_ENABLE_SIMD")
23
- end
24
- end
25
-
26
- if have_header('x86intrin.h') && have_type('__m128i', headers=['x86intrin.h']) && try_compile(<<~'SRC')
27
- #include <x86intrin.h>
28
- int main() {
29
- __m128i test = _mm_set1_epi8(32);
30
- return 0;
31
- }
32
- SRC
33
- $defs.push("-DJSON_ENABLE_SIMD")
34
- end
35
-
36
- have_header('cpuid.h')
12
+ load __dir__ + "/../simd/conf.rb"
37
13
  end
38
14
 
39
15
  create_makefile 'json/ext/generator'