json 2.21.1-java → 3.0.0.rc1-java
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/CHANGES.md +45 -0
- data/README.md +4 -84
- data/lib/json/common.rb +86 -402
- data/lib/json/ext/generator/state.rb +0 -27
- data/lib/json/ext/generator.jar +0 -0
- data/lib/json/ext/parser.jar +0 -0
- data/lib/json/ext.rb +0 -2
- data/lib/json/truffle_ruby/generator.rb +38 -80
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +24 -265
- metadata +2 -18
- data/lib/json/add/bigdecimal.rb +0 -58
- data/lib/json/add/complex.rb +0 -51
- data/lib/json/add/core.rb +0 -13
- data/lib/json/add/date.rb +0 -54
- data/lib/json/add/date_time.rb +0 -67
- data/lib/json/add/exception.rb +0 -49
- data/lib/json/add/ostruct.rb +0 -54
- data/lib/json/add/range.rb +0 -54
- data/lib/json/add/rational.rb +0 -49
- data/lib/json/add/regexp.rb +0 -48
- data/lib/json/add/set.rb +0 -48
- data/lib/json/add/string.rb +0 -35
- data/lib/json/add/struct.rb +0 -52
- data/lib/json/add/symbol.rb +0 -52
- data/lib/json/add/time.rb +0 -52
- data/lib/json/generic_object.rb +0 -67
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 703bfaea0f05e1db48e167cea887ae01eddac96188e31c15da20811c244c49b1
|
|
4
|
+
data.tar.gz: 782c24381bda5ee5f9b5aacc5f6dff81a997358b0a80aaa6768eaff8b12c68d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 16228526e82feda2b925507623b7a1fa4ea4ea370b04a9b879deea209f3fd06e18939ecf5a107bc9b6a7a2f86f5347eaaabf8e096baf34c3b82a057df34fb139
|
|
7
|
+
data.tar.gz: e11c22e4820989d2874dcec02a8a3e34dd17bbe8a73b308ac0e9694db4c86f786d34836ff0c7a01950a9989df3375b89a27a9de1a82c952bdc19c7de39c573a1
|
data/CHANGES.md
CHANGED
|
@@ -2,6 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
### Unreleased
|
|
4
4
|
|
|
5
|
+
### 2026-08-11 (3.0.0.rc1)
|
|
6
|
+
|
|
7
|
+
With the removal of the insecure `create_additions` option, `JSON.load` and `JSON.dump` are
|
|
8
|
+
now safe to use. Them being unsafe by default caused multiple security vulnerabilites in the past.
|
|
9
|
+
|
|
10
|
+
If you did depend on `create_additions`, the recommended migration is to [implement a custom serializer using
|
|
11
|
+
`JSON::Coder`](https://byroot.github.io/ruby/json/2025/08/02/whats-wrong-with-the-json-gem-api.html#the-create_additions-option).
|
|
12
|
+
|
|
13
|
+
All the mutable default options, such as `JSON.load_default_options` have been removed.
|
|
14
|
+
They were preventing Ractor compatiblity, and causing bug in libraries using JSON expecting the default behavior.
|
|
15
|
+
`JSON` methods now always behave the same unless monkey patched.
|
|
16
|
+
|
|
17
|
+
All methods options are now either keyword arguments or checked like keyword arguments, meaning
|
|
18
|
+
unknown options such as typos raise `ArgumentError`.
|
|
19
|
+
|
|
20
|
+
Duplicated keys are now rejected by default.
|
|
21
|
+
|
|
22
|
+
JavaScript comments in documents are no longer supported by default.
|
|
23
|
+
|
|
24
|
+
Numerous rarely used aliases have been removed.
|
|
25
|
+
|
|
26
|
+
* `JSON.load` defaults are now safe to use.
|
|
27
|
+
* All unknown options are now cause an `ArgumentError` rather than to be ignored.
|
|
28
|
+
* The `allow_comments` parsing option now default to `false`.
|
|
29
|
+
* The `allow_duplicate_key` option now defaults to `false`, for both parsing and generating JSON.
|
|
30
|
+
* Removed the `limit` positional argument of `JSON.dump`.
|
|
31
|
+
* Removed the `escape_slash` alias of `script_safe`.
|
|
32
|
+
* Removed `Kernel#j` and `Kernel#jj`.
|
|
33
|
+
* Removed `JSON.load_default_options`.
|
|
34
|
+
* Removed `JSON.unsafe_load_default_options`.
|
|
35
|
+
* Removed `JSON.dump_default_options`.
|
|
36
|
+
* Removed `JSON::State#[]` and `JSON::State#[]=`.
|
|
37
|
+
* Removed `JSON.unparse`.
|
|
38
|
+
* Removed `JSON.fast_generate`.
|
|
39
|
+
* Removed `JSON.fast_unparse`.
|
|
40
|
+
* Removed `JSON.pretty_unparse`.
|
|
41
|
+
* Removed `JSON.restore`.
|
|
42
|
+
* Removed `JSON::PRETTY_STATE_PROTOTYPE`.
|
|
43
|
+
* Removed the insecure `create_additions` option.
|
|
44
|
+
* Removed `JSON::GenericObject`.
|
|
45
|
+
|
|
46
|
+
### 2026-07-31 (2.21.2)
|
|
47
|
+
|
|
48
|
+
* Fix a use-after-free bug in `JSON::ResumableParser`. [GHSA-9hj4-r449-hfvc][CVE-2026-71847].
|
|
49
|
+
|
|
5
50
|
### 2026-07-13 (2.21.1)
|
|
6
51
|
|
|
7
52
|
* Fix a compilation issue on Window and Microsoft Visual C++.
|
data/README.md
CHANGED
|
@@ -14,10 +14,7 @@ UTF-16 surrogate pairs in order to be able to generate the whole range of
|
|
|
14
14
|
unicode code points.
|
|
15
15
|
|
|
16
16
|
All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
|
17
|
-
sequences on the Ruby side.
|
|
18
|
-
encoded, please use the to\_json\_raw\_object method of String (which produces
|
|
19
|
-
an object, that contains a byte array) and decode the result on the receiving
|
|
20
|
-
endpoint.
|
|
17
|
+
sequences on the Ruby side.
|
|
21
18
|
|
|
22
19
|
## Installation
|
|
23
20
|
|
|
@@ -49,8 +46,7 @@ JSON.generate(data)
|
|
|
49
46
|
```
|
|
50
47
|
|
|
51
48
|
You can also use the `pretty_generate` method (which formats the output more
|
|
52
|
-
verbosely and nicely)
|
|
53
|
-
checks generate performs, e. g. nesting deepness checks).
|
|
49
|
+
verbosely and nicely).
|
|
54
50
|
|
|
55
51
|
## Casting non native types
|
|
56
52
|
|
|
@@ -143,84 +139,12 @@ posts_json.map! { |post_json| JSON::Fragment.new(post_json) }
|
|
|
143
139
|
JSON.generate({ posts: posts_json, count: posts_json.count })
|
|
144
140
|
```
|
|
145
141
|
|
|
146
|
-
##
|
|
147
|
-
|
|
148
|
-
> [!CAUTION]
|
|
149
|
-
> You should never use `JSON.unsafe_load` nor `JSON.parse(str, create_additions: true)` to parse untrusted user input,
|
|
150
|
-
> as it can lead to remote code execution vulnerabilities.
|
|
151
|
-
|
|
152
|
-
To create a JSON document from a ruby data structure, you can call
|
|
153
|
-
`JSON.generate` like that:
|
|
154
|
-
|
|
155
|
-
```ruby
|
|
156
|
-
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
157
|
-
# => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
To get back a ruby data structure from a JSON document, you have to call
|
|
161
|
-
JSON.parse on it:
|
|
162
|
-
|
|
163
|
-
```ruby
|
|
164
|
-
JSON.parse json
|
|
165
|
-
# => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Note, that the range from the original data structure is a simple
|
|
169
|
-
string now. The reason for this is, that JSON doesn't support ranges
|
|
170
|
-
or arbitrary classes. In this case the json library falls back to call
|
|
171
|
-
`Object#to_json`, which is the same as `#to_s.to_json`.
|
|
172
|
-
|
|
173
|
-
It's possible to add JSON support serialization to arbitrary classes by
|
|
174
|
-
simply implementing a more specialized version of the `#to_json method`, that
|
|
175
|
-
should return a JSON object (a hash converted to JSON with `#to_json`) like
|
|
176
|
-
this (don't forget the `*a` for all the arguments):
|
|
177
|
-
|
|
178
|
-
```ruby
|
|
179
|
-
class Range
|
|
180
|
-
def to_json(*a)
|
|
181
|
-
{
|
|
182
|
-
'json_class' => self.class.name, # = 'Range'
|
|
183
|
-
'data' => [ first, last, exclude_end? ]
|
|
184
|
-
}.to_json(*a)
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
The hash key `json_class` is the class, that will be asked to deserialise the
|
|
190
|
-
JSON representation later. In this case it's `Range`, but any namespace of
|
|
191
|
-
the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
|
|
192
|
-
used to store the necessary data to configure the object to be deserialised.
|
|
193
|
-
|
|
194
|
-
If the key `json_class` is found in a JSON object, the JSON parser checks
|
|
195
|
-
if the given class responds to the `json_create` class method. If so, it is
|
|
196
|
-
called with the JSON object converted to a Ruby hash. So a range can
|
|
197
|
-
be deserialised by implementing `Range.json_create` like this:
|
|
198
|
-
|
|
199
|
-
```ruby
|
|
200
|
-
class Range
|
|
201
|
-
def self.json_create(o)
|
|
202
|
-
new(*o['data'])
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Now it possible to serialise/deserialise ranges as well:
|
|
208
|
-
|
|
209
|
-
```ruby
|
|
210
|
-
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
211
|
-
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
|
212
|
-
JSON.parse json
|
|
213
|
-
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
214
|
-
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
215
|
-
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
|
216
|
-
JSON.unsafe_load json
|
|
217
|
-
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
|
218
|
-
```
|
|
142
|
+
## Pretty Printing
|
|
219
143
|
|
|
220
144
|
`JSON.generate` always creates the shortest possible string representation of a
|
|
221
145
|
ruby data structure in one line. This is good for data storage or network
|
|
222
146
|
protocols, but not so good for humans to read. Fortunately there's also
|
|
223
|
-
`JSON.pretty_generate`
|
|
147
|
+
`JSON.pretty_generate` that creates a more readable
|
|
224
148
|
output:
|
|
225
149
|
|
|
226
150
|
```ruby
|
|
@@ -245,10 +169,6 @@ output:
|
|
|
245
169
|
]
|
|
246
170
|
```
|
|
247
171
|
|
|
248
|
-
There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
|
|
249
|
-
`pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
|
|
250
|
-
the `pp` library's `pp` methods.
|
|
251
|
-
|
|
252
172
|
## Security
|
|
253
173
|
|
|
254
174
|
When parsing or serializing untrusted input, parser and generator options should never be user controlled.
|