Jack Guy
Jack Guy

Reputation: 8523

jQuery .getJSON failing, syntax error?

I'm trying to parse a JSON file containing some simple key words. My function is not running. Looking at the jQuery .getJSON documentation, I realized that the most likely explanation is a syntax error. I've looked pretty thoroughly though my code, but I only learned JSON today. Can anyone help me out? Sorry, I know it's a lot of data.

JavaScript Code:

$(document).ready(function() {
$.getJSON('edit/key.json', function(data2) {
    console.log(data2);
    //more code
});

});

JSON Code:

{
"RAM": [
    {"term" : "ram"},
    {"term" : "memory"},
    {"term" : "access"},
    {"term" : "random"},
    {"term" : "component"},
    {"term" : "multi-tasking"},
    {"term" : "multi"},
    {"term" : "tasking"},
    {"term" : "gigabyte"},
    {"term" : "temporary"}
],
"Graphics Card": [
    {"term" : "component"},
    {"term" : "graphic"},
    {"term" : "graphics card"},
    {"term" : "processing"},
    {"term" : "processors"},
    {"term" : "unit"},
    {"term" : "card"},
    {"term" : "3D"},
    {"term" : "image"},
    {"term" : "media"},
    {"term" : "gaming"},
    {"term" : "game"},
    {"term" : "nvidia"},
    {"term" : "amd"},
    {"term" : "chip"},
    {"term" : "clock"},
    {"term" : "speed"},
    {"term" : "GPU"},
    {"term" : "video"},
    {"term" : "DVI"},
    {"term" : "DisplayPort"},
    {"term" : "HDMI"}
],
"Ports": [
    {"term" : "port"},
    {"term" : "interface"},
    {"term" : "external"},
    {"term" : "USB"},
    {"term" : "devices"},
    {"term" : "3.0"},
    {"term" : "2.0"},
    {"term" : "VGA"},
    {"term" : "DVI"},
    {"term" : "HDMI"},
    {"term" : "display"},
    {"term" : "port"},
    {"term" : "memory"},
    {"term" : "card"},
    {"term" : "SD"},
    {"term" : "stick"},
    {"term" : "ethernet"},
    {"term" : "input"},
    {"term" : "output"},
],
"CPU": [
    {"term" : "cpu"},
    {"term" : "central"},
    {"term" : "processing"},
    {"term" : "unit"},
    {"term" : "computing"},
    {"term" : "compute"},
    {"term" : "intel"},
    {"term" : "AMD"},
    {"term" : "processors"},
    {"term" : "desktop"},
    {"term" : "laptop"},
    {"term" : "i3"},
    {"term" : "i5"},
    {"term" : "i7"},
    {"term" : "core"},
    {"term" : "turbo"},
    {"term" : "boost"},
    {"term" : "gaming"},
    {"term" : "media"},
    {"term" : "overclocked"},
    {"term" : "clock"},
    {"term" : "speed"}
],
"Hard Drive": [
    {"term" : "store"},
    {"term" : "data"},
    {"term" : "hard"},
    {"term" : "drive"},
    {"term" : "video"},
    {"term" : "music"},
    {"term" : "picture"},
    {"term" : "document"},
    {"term" : "media"},
    {"term" : "processor"},
    {"term" : "gigabyte"},
    {"term" : "terabyte"},
    {"term" : "rpm"},
    {"term" : "cache"}
],
"Operating System": [
    {"term" : "operating"},
    {"term" : "system"},
    {"term" : "os"},
    {"term" : "device"},
    {"term" : "windows"},
    {"term" : "mac"},
    {"term" : "linux"},
    {"term" : "ubuntu"},
    {"term" : "chrome"},
    {"term" : "xp"},
    {"term" : "vista"},
    {"term" : "7"},
    {"term" : "8"},
    {"term" : "home"},
    {"term" : "premium"},
    {"term" : "professional"},
    {"term" : "ultimate"},
]}

Upvotes: 0

Views: 449

Answers (1)

dcasadevall
dcasadevall

Reputation: 316

You have a couple of syntax errors indeed.

There is an extra comma in the ports array. {"term" : "output"} has a comma after it, and it shouldn't, being the last element.

Same thing happens with the last element of the array "Operating System". The last element {"term", "ultimate"} should have no comma after it.

This is the correct code that should parse fine:

{
"RAM": [
    {"term" : "ram"},
    {"term" : "memory"},
    {"term" : "access"},
    {"term" : "random"},
    {"term" : "component"},
    {"term" : "multi-tasking"},
    {"term" : "multi"},
    {"term" : "tasking"},
    {"term" : "gigabyte"},
    {"term" : "temporary"}
],
"Graphics Card": [
    {"term" : "component"},
    {"term" : "graphic"},
    {"term" : "graphics card"},
    {"term" : "processing"},
    {"term" : "processors"},
    {"term" : "unit"},
    {"term" : "card"},
    {"term" : "3D"},
    {"term" : "image"},
    {"term" : "media"},
    {"term" : "gaming"},
    {"term" : "game"},
    {"term" : "nvidia"},
    {"term" : "amd"},
    {"term" : "chip"},
    {"term" : "clock"},
    {"term" : "speed"},
    {"term" : "GPU"},
    {"term" : "video"},
    {"term" : "DVI"},
    {"term" : "DisplayPort"},
    {"term" : "HDMI"}
],
"Ports": [
    {"term" : "port"},
    {"term" : "interface"},
    {"term" : "external"},
    {"term" : "USB"},
    {"term" : "devices"},
    {"term" : "3.0"},
    {"term" : "2.0"},
    {"term" : "VGA"},
    {"term" : "DVI"},
    {"term" : "HDMI"},
    {"term" : "display"},
    {"term" : "port"},
    {"term" : "memory"},
    {"term" : "card"},
    {"term" : "SD"},
    {"term" : "stick"},
    {"term" : "ethernet"},
    {"term" : "input"},
    {"term" : "output"}
],
"CPU": [
    {"term" : "cpu"},
    {"term" : "central"},
    {"term" : "processing"},
    {"term" : "unit"},
    {"term" : "computing"},
    {"term" : "compute"},
    {"term" : "intel"},
    {"term" : "AMD"},
    {"term" : "processors"},
    {"term" : "desktop"},
    {"term" : "laptop"},
    {"term" : "i3"},
    {"term" : "i5"},
    {"term" : "i7"},
    {"term" : "core"},
    {"term" : "turbo"},
    {"term" : "boost"},
    {"term" : "gaming"},
    {"term" : "media"},
    {"term" : "overclocked"},
    {"term" : "clock"},
    {"term" : "speed"}
],
"Hard Drive": [
    {"term" : "store"},
    {"term" : "data"},
    {"term" : "hard"},
    {"term" : "drive"},
    {"term" : "video"},
    {"term" : "music"},
    {"term" : "picture"},
    {"term" : "document"},
    {"term" : "media"},
    {"term" : "processor"},
    {"term" : "gigabyte"},
    {"term" : "terabyte"},
    {"term" : "rpm"},
    {"term" : "cache"}
],
"Operating System": [
    {"term" : "operating"},
    {"term" : "system"},
    {"term" : "os"},
    {"term" : "device"},
    {"term" : "windows"},
    {"term" : "mac"},
    {"term" : "linux"},
    {"term" : "ubuntu"},
    {"term" : "chrome"},
    {"term" : "xp"},
    {"term" : "vista"},
    {"term" : "7"},
    {"term" : "8"},
    {"term" : "home"},
    {"term" : "premium"},
    {"term" : "professional"},
    {"term" : "ultimate"}
]}

Upvotes: 2

Related Questions