title: How to Customize json result in Mvc Web Api
body: <p>In my Web Api application I return both xml and json result. The format is specified in the URL.Based on the url I specified it in Global.asax and return the result. Global.asax is</p>
  
  <pre><code>protected void Application_Start()
  {
      GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(
       new QueryStringMapping("format", "json", new MediaTypeHeaderValue("application/json")));
      GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(
          new QueryStringMapping("format", "xml", new MediaTypeHeaderValue("application/xml")));
      GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;//for xml attribute
  }
  </code></pre>
  
  <p>Class for serialization is</p>
  
  <pre><code>public class ContinentData
  {
  [JsonProperty(PropertyName = "id")]
  [XmlElement(ElementName = "id")]
  public string Id { get; set; }
  [XmlElement(ElementName = "name")]
  [JsonProperty(PropertyName = "name")]
  public string Name { get; set; }
  }
  [XmlRoot("response_item")]
  public class ContinentsList
  {
  [XmlArray("regions")]
  [XmlArrayItem("region")]
  [JsonProperty(PropertyName = "regions")]
  public List&lt;ContinentData&gt; Region { get; set; }
  public ContinentsList()
  {
      Region = new List&lt;ContinentData&gt;();
  }
  }
  [XmlRoot("response")]
  public class Continents
  {
  [XmlElement("response_item")]
  public ContinentsList Regions { get; set; }
  public Continents()
  {
      Regions = new ContinentsList();
  }
  }
  </code></pre>
  
  <p>and i get the xml result, Which is the expected output</p>
  
  <pre><code>&lt;response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;response_item&gt;
   &lt;regions&gt;
    &lt;region&gt;
     &lt;id&gt;AFRICA&lt;/id&gt;
     &lt;name&gt;Africa&lt;/name&gt;
    &lt;/region&gt;
   &lt;/response_item&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>And the Json result</p>
  
  <pre><code>{"Regions":{"regions":[{"id":"AFRICA","name":"Africa"}]}}
  </code></pre>
  
  <p>but I really want the json like</p>
  
  <pre><code>[{"regions":[{"id":"AFRICA","name":"Africa"}]}]
  </code></pre>
  
  <p>I return the content in the controller by</p>
  
  <pre><code>var regions = _continentService.GetAllContinents();
  return Ok(regions);
  </code></pre>
  
  <p>Is there any generalize method for customize the result? How could i do this?</p>