#author("2022-07-08T15:08:19+00:00","default:src128","src128") &tag(Rails/JSON); *目次 [#y25de75b] #contents *関連ページ [#if6cefb2] *参考情報 [#h11cacd4] *ActiveRecordのサブクラスをJSONに変換 [#jc79ea3b] -to_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" } }}