title: What data structure is select2 expecting from the server and how should it be handled?
body: <p>What data structure is <a href="https://select2.github.io/" rel="nofollow noreferrer">select2</a> (v4.0.3) expecting from the server and how should it be handled?  </p>
  
  <p>The question is asked on the official FAQ <a href="https://select2.github.io/options.html#what-should-the-results-returned-to-select2-look-like" rel="nofollow noreferrer">here</a>, but there is no answer.   </p>
  
  <p>I have tried several variations of data structure, but based on this <a href="http://www.southcoastweb.co.uk/jquery-select2-v4-ajaxphp-tutorial" rel="nofollow noreferrer">tutorial</a> and this <a href="http://jsfiddle.net/marcrazyness/XMAq2/" rel="nofollow noreferrer">jsFiddle</a>, have assumed what should be returned from the server is a list/array of objects/dicts, eg:</p>
  
  <pre><code>matches = [{"id":"1", "tag":"Python"},{"id":"2", "tag":"Javascript"},{"id":"3", "tag":"MongoDB"}]
  </code></pre>
  
  <p>I have tried this format with the following Javascript:</p>
  
  <pre><code>$("#my_select").select2({
  ajax: {
  url: "/tag_search",
  dataType: 'json',
  delay: 250,
  data: function (params) {
  return {
  q: params.term // search term
  };
  },
  processResults: function (data) {
  return {
  results: data.matches
  };
  },
  cache: true
  },
  minimumInputLength: 2,
  tags: true,
  tokenSeparators: [",", " "],
  maximumSelectionLength: 5
  });
  </code></pre>
  
  <p>Firebug results for search on <code>Py</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/oZvze.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oZvze.png" alt="enter image description here"></a> </p>
  
  <p>The search area just displays this:</p>
  
  <p><a href="https://i.stack.imgur.com/08AGz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/08AGz.png" alt="enter image description here"></a></p>
  
  <p>I am expecting all matches to be showing in the dropdown below the search area.  </p>