I am really new about Ruby development. I am trying to create a json file with strings. My json file like below. Can you help to me
{
"App":{
"properties":{"color":"red"},
"screens":[
{"id":"page1", "properties":{"color":"red"}, "elements":[
{"type":"txtbox", "properties":{"color":"red"}},
{"type":"button", "properties":{"color":"red"}}
]
},
{"id":"page2", "properties":{"color":"red"}, "elements":[
{"type":"txtbox", "properties":{"color":"red"}},
{"type":"button", "properties":{"color":"red"}}
]
}
]
}
}
You can parse JSON with ruby from a hash:
require 'json'
my_hash = JSON.parse('{"hello": "goodbye"}')
puts my_hash["hello"] => "goodbye"
Or generate it from a hash:
require 'json'
my_hash = {:hello => "goodbye"}
puts JSON.generate(my_hash) => "{\"hello\":\"goodbye\"}"
Have a look at the JSON documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With