JSON.parse exception in Meteor Server

console.log(JSON) ==> {}
console.log(JSON.parse(staticSchools)) ==> SyntaxError: Unexpected token s

Meteor.startup(
function () {
var querySchools = Schools.find(),
staticSchools = Assets.getText(‘static/schools.json’),
hasDocument = querySchools.count() > 0,
schools = hasDocument
? querySchools.fetch()
: staticSchools;

console.log(JSON.parse(staticSchools));

}
);

  • This codes reside on /server and throw exception there but works fine on /client

I’ve seen a similar error thrown using a similar pattern, have you double checked that the JSON is definitely valid syntax?

Also per docs, Assets.getText should only be callable on the server, so you might be mixed up w/r/t/ client & server?

Found it. Indeed,JSON invalid syntax was the problem. All keys and values need to be wrapped in double quote “”. Got it fixed.

Not sure of context, but EJSON might be of help - it supports Date and binary as opposed to regular JSON. When I ran into a similar problem it was because of Date, EJSON cleared it right up!