title: Elasticsearch returning invalid JSON
body: <p>I have an interesting issue in Elasticsearch. When performing searches it returns invalid json, such that when I try to run, <code>JSON.parse(response)</code> it results in a parse error (Node.js).</p>
  
  <p>Here's what the response data looks like:</p>
  
  <pre><code>{
      "took":5,
      "timed_out":false,
      "_shards": {
          "total":5,
          "successful":5,
          "failed":0
      },
      "hits": {
          "total":28,
          "max_score": 1.1264253,
          "hits": [
              {
                  "_index": "myindex",
                  "_type": "v1",
                  "_id":"AUsTvTc0HrKvNpcAkwza",
                  "_score": 1.1264253,
                  "_source": {
                      "term":"Value"
                  },
              },   
              {
                  "_index": "myindex",
                  "_type": "v1",
                  "_id":"BRxvTMggf5NTMnxwzalF",
                  "_score": 0.1328153,
                  "_source": {
                      "term":"Other Value"
                  },
              }  
          ]
     }
  }
  </code></pre>
  
  <p>As you'll notice after the <code>_source</code> property there is a comma, even though it's the last property in that object.</p>
  
  <p>In order to be able to parse this I have to run the following code:</p>
  
  <pre><code>var json = response.replace(/,\s+}/g, '}');
      json = JSON.parse(json);
  </code></pre>
  
  <p>Then it will parse, but this is simply a band-aid. What I can't figure out is, <em>WHY</em> is Elasticsearch returning my JSON like that?</p>
  
  <p>Any help is much appreciated!</p>
  
  <p>Eric</p>