module Kernel
Private Instance Methods
JSON(object, *args)
click to toggle source
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.
# File json/lib/json/common.rb, line 873 def JSON(object, *args) if object.is_a?(String) return JSON.parse(object, args.first) elsif object.respond_to?(:to_str) str = object.to_str if str.is_a?(String) return JSON.parse(object.to_str, args.first) end end JSON.generate(object, args.first) end
j(*objs)
click to toggle source
Outputs objs to STDOUT as JSON
strings in the shortest form, that is in one line.
# File json/lib/json/common.rb, line 851 def j(*objs) objs.each do |obj| puts JSON::generate(obj, :allow_nan => true, :max_nesting => false) end nil end
jj(*objs)
click to toggle source
Outputs objs to STDOUT as JSON
strings in a pretty format, with indentation and over many lines.
# File json/lib/json/common.rb, line 860 def jj(*objs) objs.each do |obj| puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false) end nil end