Tsallaka zuwa abun ciki
Justice Tech School

JSON

require json then to_json and JSON.parse convert data.

Example
require "json"
data = { name: "Ada", tags: ["a", "b"] }
s = data.to_json
puts s
puts JSON.parse(s)["tags"].inspect
puts JSON.parse(s, symbolize_names: true)[:name]

Result

{"name":"Ada","tags":["a","b"]}
["a", "b"]
Ada

Exercise

Parse text.

JSON.(s)

Quiz Test

What does to_json return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.