A: 

Call the URL or the XHR request directly in your browser's address bar, do a view-source and paste the result into and IDE that understands JavaScript. You'll probably spot a misplaced quote or something.

At least you'll be able to remove chunks of it until you find the offending syntax if nothing else.

Diodeus
So what it's actually doing in the instances where it's throwing syntax errors is loading a normal webpage with DOCTYPE and all, and then trying to parse that. It throws the syntax error because it thinks I'm trying to feed it a JSON feed, when really I'd rather have it return false or an error message.
Daniel Bachhuber
+3  A: 

You can bind a function to global ajaxerror events

$(document).ajaxError(function(event, request, ajaxOptions, thrownError){
  if ( 4==request.readyState) { // failed after data has received
    alert(ajaxOptions['url'] + " did not return valid json data");
  }
  else {
    alert("something else wnet wrong");
  }
});
or use $.ajax() instead of $.getJSON()
function foo() {
  // $.getJSON("http://localhost/test.txt", function(data){});
  $.ajax({
    type: "GET",
    url: "http://localhost/test.txt",
    success: function (data, textStatus) {
      alert("succuess");
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      alert("request failed: " + textStatus);
    },
    dataType: "json"
  });
}

edit: But you might want to keep in mind that both ajax(dataType:"json") and getJSON() (which simply invokes .ajax(dataType:"json") boil down to data = window["eval"]("(" + data + ")") ...this might not be what you want if you don't know what (arbitrary) data your script requests. And this could explain why firebug is catching a syntax error when you feed it an html document instead of json data.
In that case better request dataType:"string" und run the data through a fully fledged json parser lib.

VolkerK
Thanks for the detailed code response, VolkerK. I think both of these examples would work if the URL itself was returning an error of some sort. I tried including your first example. The issue, however, is that the URL loads fine but it isn't a valid JSON object. When jQuery tries to parse it, it throws a syntax error on the data provided.
Daniel Bachhuber
Both code snippets were able to tell a mere connection problem from data format trouble when I tested it. I'd prefer the .ajax() approach. Then textStatus is =="parserror" if the data isn't JSON.
VolkerK
Odd, still no dice. I changed my process from $.getJSON to $.ajax, but Firebug still throws the syntax error instead of any alert messages. Thanks for the help in any regard.
Daniel Bachhuber
I'm testing with jquery 1.3.2, but anyway: see my last post-edit...
VolkerK
Ah, good point. I was thinking that I might have to include an intermediate step where I can check the URL data myself. I'll try that out in the morning.
Daniel Bachhuber
+1 for spotting the window.eval problem
chendral
Finally came back to this one and figured it out. I'll answer in depth too, but the short of it is that jQuery doesn't let you load anything other than a script or JSON from an external domain. I ended up having to write another script on my server that jQuery calls.
Daniel Bachhuber
A: 

Adding to Diodeus' answer, paste your potentially offending JSON into here this tool: http://jsonformatter.curiousconcept.com/

If you have firebug, you might even be able to hack together a way to use the site a service programmatically, though that may be frowned upon.

Stuart Branham
A: 

Thanks to all who answered. Because I was calling a JSON feed from an external domain, I wasn't able to just use jQuery's AJAX functionality and pull the feed as "text" instead of "json". jQuery only allows you to pull "json" and "script" from a remote source.

What I ended up doing instead was writing a PHP script to make the external call that lived on my own server. I use jQuery AJAX to call this, pass the requested source in the URL, and then grab that as "text." I then run my own check to ensure that it's properly formatted JSON, and then parse it with another library. jQuery doesn't have the ability to parse JSON at the moment; $.getJSON only works if you pass a URL to it.

Daniel Bachhuber