Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Alberto Centelles
Alberto Centelles
8,356 Points

Foursquare API

Here is my code. The console says it has an "Uncaught SyntaxError: Unexpected token ILLEGAL " when it gets to "var script = '{".

I copy it here:


<h2>JSON Object Creation in JavaScript</h2>

<p id="demo"></p>

var script = '{
meta: {
code: 200
notifications: [
type: "notificationTray"
item: {
unreadCount: 8
response: {
categories: [
id: "4d4b7104d754a06370d81259"
name: "Arts & Entertainment"
pluralName: "Arts & Entertainment"
shortName: "Arts & Entertainment"
icon: {
prefix: "https://ss3.4sqi.net/img/categories_v2/arts_entertainment/default_"
suffix: ".png"

var obj = JSON.parse(script);



Thank you very much

1 Answer

A good way to debug these kinds of issues if you're not seeing the issue is to prune your JSON object down until you see where it's causing the issue. I think in this case, it's because your key names need to be strings, so "meta" instead of meta, etc.

20,306 Points

I agree with Aimee Ault . Try to validate your json object in an online JSON validator - jsonlint.com is a good choice to start with.