I just started working with node.js and json objects in my college course. One of our assignments this week was to create a few json objects and extract parts of the object
the solution is to use JSON.stringify
as follows
var target=JSON.parse(JSON.stringify(source));
Your colleges
variable is already a valid JavaScript Object. You do not have to use JSON.parse
on it.
JSON.parse
expects a String
as first argument, but you provide an Object
. Thus it is coerced to a String
looking like the one you see in the Error message.
For the rest of your code, you might want to take a look at Express or Zappa to be able to write the code a bit more compact ;)