Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

JSON.[]

(untyped object, ?::JSON::options opts) -> untyped
JSON[object] → new_array or new_string

If object is a String, calls JSON.parse with object and opts (see method parse):

Example
json = '[0, 1, null]'
JSON[json]# => [0, 1, nil]

Otherwise, calls JSON.generate with object and opts (see method generate):

Example
ruby = [0, 1, nil]
JSON[ruby] # => '[0,1,null]'
See also .on_mixed_keys_hash #dump also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0