123456789_123456789_123456789_123456789_123456789_

Module: Kernel

Relationships & Source Files
Defined in: ext/json/lib/json/common.rb

Instance Method Summary

  • j(*objs) private

    Outputs objs to STDOUT as #JSON strings in the shortest form, that is in one line.

  • jj(*objs) private

    Outputs objs to STDOUT as #JSON strings in a pretty format, with indentation and over many lines.

  • JSON(object, opts = nil) private

    If object is string-like, parse the string and return the parsed result as a Ruby data structure.

Instance Method Details

j(*objs) (private)

Outputs objs to STDOUT as #JSON strings in the shortest form, that is in one line.

[ GitHub ]

  
# File 'ext/json/lib/json/common.rb', line 1065

def j(*objs)
  if RUBY_VERSION >= "3.0"
    warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
  else
    warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1
  end

  objs.each do |obj|
    puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
  end
  nil
end

jj(*objs) (private)

Outputs objs to STDOUT as #JSON strings in a pretty format, with indentation and over many lines.

[ GitHub ]

  
# File 'ext/json/lib/json/common.rb', line 1080

def jj(*objs)
  if RUBY_VERSION >= "3.0"
    warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
  else
    warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1
  end

  objs.each do |obj|
    puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
  end
  nil
end

JSON(object, opts = nil) (private)

If object is string-like, parse the string and return the parsed result as a Ruby data structure. Otherwise, generate a JSON text from the Ruby data structure object and return it.

The opts argument is passed through to generate/parse respectively. See generate and parse for their documentation.

[ GitHub ]

  
# File 'ext/json/lib/json/common.rb', line 1099

def JSON(object, opts = nil)
  JSON[object, opts]
end