Module
In: lib/json/common.rb

Methods

JSON   j   jj  

Public Instance methods

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.

[Source]

# File lib/json/common.rb, line 336
  def JSON(object, opts = {})
    if object.respond_to? :to_str
      JSON.parse(object.to_str, opts)
    else
      JSON.generate(object, opts)
    end
  end

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

[Source]

# File lib/json/common.rb, line 314
  def j(*objs)
    objs.each do |obj|
      puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
    end
    nil
  end

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

[Source]

# File lib/json/common.rb, line 323
  def jj(*objs)
    objs.each do |obj|
      puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
    end
    nil
  end

[Validate]