-1
# JSON Parsing example
require "rubygems"
require "json"

string = '{"desc":{"someKey":"someValue","anotherKey":"value"},"main_item":{"stats":{"a":8,"b":12,"c":10}}}'
parsed = JSON.parse(string) # returns a hash

p parsed["desc"]["someKey"]
p parsed["main_item"]["stats"]["a"]

# Read JSON from a file, iterate over objects
file = open("shops.json")
json = file.read

parsed = JSON.parse(json)

parsed["shop"].each do |shop|
  p shop["id"]
end

is that predict? Thanks!!

BufBills
  • 8,005
  • 12
  • 48
  • 90

1 Answers1

0

It's Kernel#p method.

According to the documentation:

p(obj) → obj click to toggle source
p(obj1, obj2, ...) → [obj, ...]
p() → nil

For each object, directly writes obj.inspect followed by a newline to the program’s standard output.

falsetru
  • 357,413
  • 63
  • 732
  • 636