title: Javascript - Unable to read json key values - Unexpected token i in JSON at position 1 - sql query output problem
body: <p>I'ved got this string generated from sql query (basically using ARRAY_AGG and some cases to format the output) that looks like this</p>
  <pre><code>{id:2,name_of_division:'super department1',attendance_radius:1000}
  </code></pre>
  <p>However, in javascript, I cant get any of the key values and its also causing JSON parse error.
  I'ved tried validating this JSON and it looks perfectly fine.</p>
  <p>Here are some of the troubleshooting, I have no idea what is causing it</p>
  <pre><code>console.log(clean_div_array_var[i].toString());
  output ==&gt; {id:2,name_of_division:'super department1',attendance_radius:1000}
  
  console.log(&quot;id:&quot; + clean_div_array_var[i].id);
  output ==&gt; id:undefined
  
  console.log(&quot;name_of_division:&quot; + clean_div_array_var[i].name_of_division);
  output ==&gt; name_of_division:undefined
  
  
  JSON.parse(clean_div_array_var[i]);
  output ==&gt;
  VM2561:1 Uncaught SyntaxError: Unexpected token i in JSON at position 1
      at JSON.parse (&lt;anonymous&gt;)
      at get_all_key_of_div_array ((index):817)
      at render ((index):2321)
      at jquery.dataTables.min.js:18
      at Object.b.fnGetData (jquery.dataTables.min.js:12)
      at B (jquery.dataTables.min.js:17)
      at Ha (jquery.dataTables.min.js:25)
      at O (jquery.dataTables.min.js:16)
      at jquery.dataTables.min.js:49
      at i (jquery.dataTables.min.js:35)
   
  </code></pre>
  <p>I even try to stringify, then somehow remove quotes (I dont understand why this even appears) and then JSON parse. Same problem.</p>
  <pre><code>stringifyvar = JSON.stringify(clean_div_array_var[i])
  output ==&gt; &quot;{id:2,name_of_division:'super department1',attendance_radius:1000}&quot;
  
  stringifyvar = stringifyvar.split('\&quot;').join('');
  console.log(&quot;stringify remove quote:&quot; + stringifyvar);
  output ==&gt; stringify remove quote:{id:2,name_of_division:'super department1',attendance_radius:1000}
  
  parsed_json_data = JSON.parse(stringifyvar);
  
  output ==&gt;
  VM2503:1 Uncaught SyntaxError: Unexpected token i in JSON at position 1
      at JSON.parse (&lt;anonymous&gt;)
      at get_all_key_of_div_array ((index):816)
      at render ((index):2320)
      at jquery.dataTables.min.js:18
      at Object.b.fnGetData (jquery.dataTables.min.js:12)
      at B (jquery.dataTables.min.js:17)
      at Ha (jquery.dataTables.min.js:25)
      at O (jquery.dataTables.min.js:16)
      at jquery.dataTables.min.js:49
      at i (jquery.dataTables.min.js:35)
  </code></pre>
  <p>How can I read any of the keys properly from this json</p>