title: Rails 4 how to change structure of validation errors
body: <p>Is there a way to change the structure of general validation errors for JSON such as</p>
  
  <p>presence and uniqueness</p>
  
  <p>I have below code in model folder with presence_validator.rb</p>
  
  <pre><code>class PresenceValidator &lt; ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      unless value.present?
        record.errors[attribute] &lt;&lt; (options[:message] || "is not present")
      end
    end
  end
  </code></pre>
  
  <p>But this doesn't seem to be working with message.</p>
  
  <p>I would like the error format to be like:</p>
  
  <pre><code>{
    "errors": [
       { "key": "aaass", "value": "adasasdas" },
       { "key": "aadaass", "value": "adasas132das" }
    ]
  }
  </code></pre>
  
  <p>Current JSON fail:</p>
  
  <pre><code>{
    "name": [
      "Requires name"
    ]
  }
  </code></pre>