{"action":"created","issue":{"url":"https://api.github.com/repos/toptal/chewy/issues/221","labels_url":"https://api.github.com/repos/toptal/chewy/issues/221/labels{/name}","comments_url":"https://api.github.com/repos/toptal/chewy/issues/221/comments","events_url":"https://api.github.com/repos/toptal/chewy/issues/221/events","html_url":"https://github.com/toptal/chewy/issues/221","id":95900554,"number":221,"title":"Generating JSON without import","user":{"login":"codezomb","id":424246,"avatar_url":"https://avatars.githubusercontent.com/u/424246?v=3","gravatar_id":"","url":"https://api.github.com/users/codezomb","html_url":"https://github.com/codezomb","followers_url":"https://api.github.com/users/codezomb/followers","following_url":"https://api.github.com/users/codezomb/following{/other_user}","gists_url":"https://api.github.com/users/codezomb/gists{/gist_id}","starred_url":"https://api.github.com/users/codezomb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codezomb/subscriptions","organizations_url":"https://api.github.com/users/codezomb/orgs","repos_url":"https://api.github.com/users/codezomb/repos","events_url":"https://api.github.com/users/codezomb/events{/privacy}","received_events_url":"https://api.github.com/users/codezomb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-19T09:14:45Z","updated_at":"2015-07-19T09:23:38Z","closed_at":null,"body":"I'm using ES (via chewy) to serve up our JSON in a few places without hitting the database. For us, this works really well as it gives us consistency between search and non-search queries, as well as being extremely fast. However, there's a few places I want to convert an AR object to the same JSON format, without actually having to maintain a different JSON mapping vs the ES mapping. I've been digging around a bit, but I've been unable to figure this out.\r\n\r\nIs this possible? For example:\r\n\r\n```ruby\r\n# GET /articles\r\nrender json: ArticleIndex.filter { category == 'foo' }\r\n  .map { |a| a._data[\"_source\"] }.to_json\r\n\r\n# POST /articles (I want to match the ES mapping here)\r\nrender Article.create(article_params).to_json\r\n```"},"comment":{"url":"https://api.github.com/repos/toptal/chewy/issues/comments/122641721","html_url":"https://github.com/toptal/chewy/issues/221#issuecomment-122641721","issue_url":"https://api.github.com/repos/toptal/chewy/issues/221","id":122641721,"user":{"login":"pyromaniac","id":88852,"avatar_url":"https://avatars.githubusercontent.com/u/88852?v=3","gravatar_id":"","url":"https://api.github.com/users/pyromaniac","html_url":"https://github.com/pyromaniac","followers_url":"https://api.github.com/users/pyromaniac/followers","following_url":"https://api.github.com/users/pyromaniac/following{/other_user}","gists_url":"https://api.github.com/users/pyromaniac/gists{/gist_id}","starred_url":"https://api.github.com/users/pyromaniac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyromaniac/subscriptions","organizations_url":"https://api.github.com/users/pyromaniac/orgs","repos_url":"https://api.github.com/users/pyromaniac/repos","events_url":"https://api.github.com/users/pyromaniac/events{/privacy}","received_events_url":"https://api.github.com/users/pyromaniac/received_events","type":"User","site_admin":false},"created_at":"2015-07-19T09:23:37Z","updated_at":"2015-07-19T09:23:37Z","body":"There is no direct way to do it currently, but you are able to use something like https://github.com/toptal/chewy/blob/master/lib/chewy/type/import.rb#L153 - i.e. take ArticleIndex::Article.root_object and call compose on it with newly created article."}}