require 'json'

class User
  attr_accessor :name, :age

  def initialize(name, age)
    @name = name
    @age = age
  end

  def to_json(*_args)
    { name: @name, age: @age }.to_json
  end
end

user = User.new("Alice", 30)
puts user.to_json