I would like to do something like this:
require 'json' class Person attr_accessor :fname, :lname end p = Person.new p.fname = "Mike" p.lname = "Smith" p.to_json
Is it possible?
Yes, you can do it with to_json.
to_json
You may need to require 'json' if you're not running Rails.
require 'json'
2.1m questions
2.1m answers
60 comments
57.0k users