Add values to Ruby JSON Object

Viewed 13877

I am working on Ruby on Rails. I have JSON object like this in my database:

{"data":[
    {"name":"A", "available":"1"},
    {"name":"B", "available":"0"}
]}

I want to update this by adding another record and it should look like:

{"data":[
        {"name":"A", "available":"1"},
        {"name":"B", "available":"0"},
        {"name":"C","available":"1"}
    ]}

How can I do this?

2 Answers
Related