&tag(Rails/JSON);
#pre{{
book = Book.new
book.title = "abc"
json = book.to_json
puts JSON.pretty_generate(JSON.parse(json))# 以下の出力が得られる。custom_titleはテーブルに対応していないフィールド(追加方法は後述)。 {
"id": null, "title": "abc", "author": null, "summary": null, "created_at": null, "updated_at": null, "custom_title": "custom abc"
} }}