title: Reading Json Form data golang
body: <p>I am sending form data in JSON &amp; serialize format to golang server using ajax. I am not able to read those data.</p>
  
  <p>I am using <code>kataras/iris</code> golang framework.</p>
  
  <p>Below is my code -</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>(function ($) {
      $.fn.serializeFormJSON = function () {
          var o = {};
          var a = this.serializeArray();
          $.each(a, function () {
              if (o[this.name]) {
                  if (!o[this.name].push) {
                      o[this.name] = [o[this.name]];
                  }
                  o[this.name].push(this.value || '');
              } else {
                  o[this.name] = this.value || '';
              }
          });
          return o;
      };
  })(jQuery);
  
  var Contact = {
      sendMessage: function() {
        return m.request({
            method: "POST",
            url: "/send/message",
            data: JSON.stringify(jQuery('#contact-form').serializeFormJSON()),
            withCredentials: true,
            headers: {
                'X-CSRF-Token': 'token_here'
            }
        })
      }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!-- Data looks like below, what is sent --&gt;
  "{\"first_name\":\"SDSDFSJ\",\"csrf.Token\":\"FjtWs7UFqC4mPlZU\",\"last_name\":\"KJDHKFSDJFH\",\"email\":\"DJFHKSDJFH@KJHFSF.COM\"}"</code></pre>
  </div>
  </div>
  </p>
  
  <p>And I am trying to fetch the data from server using below code - </p>
  
  <pre><code>// Contact form
  type Contact struct {
      FirstName string `json:"first_name"`
      LastName  string `json:"last_name"`
      Email     string `json:"email"`
  }
  
  contact := Contact{}
  contact.FirstName = ctx.FormValue("first_name")
  contact.LastName = ctx.FormValue("last_name")
  contact.Email = ctx.FormValue("email")
  ctx.Writef("%v", ctx.ReadForm(contact))
  </code></pre>
  
  <p>My all data is blank, How to grab the data? I am using <a href="https://github.com/kataras/iris" rel="nofollow noreferrer">https://github.com/kataras/iris</a> golang framework.</p>