Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

JSON.[]

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 .create_fast_state .create_id also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1