title: How to JSON Serialize the MVC ModelState object for jQuery Validation consumption?
body: <p>I'm unable to figure out the correct JSON object I need to pass into jQuery validation's showErrors() method. So on the client I have JavaScript:</p>
  
  <pre><code>  var validator = $("form").validate();
    validator.showErrors(modelstate_json);
  </code></pre>
  
  <p>And server-side extracting ModelState errors into JSON is easily done</p>
  
  <pre><code>var errors = (from e in ModelState where e.Value.Errors.Count &gt; 0 select e)
  ToDictionary(x =&gt; 
   x.Key, 
   x =&gt; x.Value.Errors
  .Select(y =&gt; y.ErrorMessage)
  .Concat(x.Value.Errors.Where(y =&gt; y.Exception != null)
  .Select(y =&gt; y.Exception.Message)));
  
  JsonConvert.SerializeObject(errors);
  </code></pre>
  
  <p>Which gives me something like</p>
  
  <pre><code>'{"Name": "Max 30 characters"}'
  </code></pre>
  
  <p>But passing this fragment to showErrors() does not trigger validation and display the message. </p>
  
  <p>If I know the correct JSON to feed showErros() then I am hoping I can reverse engineer my serialization routine. </p>
  
  <p>Thanks</p>