Currently, I am exploring how to efficiently convert an array of arrays into a JSON string for retrieval through a RESTful API.
On my server, data is fetched from a database in the format:
{"user":"some name","age":number}
To ensure compliance with the REST specifications, I need to format the data as JSON. At times, there might be a single record to return and sometimes multiple records are involved. Here's a snippet of code I am experimenting with to validate the syntax for JSON conversion:</p>
<pre><code>var resultSet = [];
resultSet.push({"user":"John Doe","age":43});
resultSet.push({"user":"Jane doe","age":29});
var myJson = JSON.parse(resultSet);
Upon executing this script with nodejs, I encounter the error message:
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
I welcome any suggestions or insights on resolving this issue. Your assistance would be highly valued.