File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Getting message as Invalid JSON Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting message as Invalid JSON" Watch "Getting message as Invalid JSON" New topic

Getting message as Invalid JSON

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I am creating a JSON Data inside my servlet , as shwon :

This is my JSP Page using Juery

I am getting mesage as Invalid JSON
to validate the json i have used

and it showed a parse error as

syntax error, unexpected TINVALID, expecting TSTRING or '}' at line 2
Parsing failed

please tell me how to solve this

Save India From Corruption - Anna Hazare.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
I would certainly write that String that is supposed to be JSON to a log file in addition to sending it to the response so it can be examined carefully.

Trying to figure out what was actually written by looking at the code is unlikely to spot the flaw.

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

i solved it by changing jquery version to 1.3 from 1.5 .
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

I'd hardly called that "solved". Do you really think that makes sense as opposed to fixing the invalid JSON?

[Asking smart questions] [About Bear] [Books by Bear]
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 544
I would suggest using the Java APIs for JSON. Those are available at Java JSON API. That will help you not to get these kind of errors.

parampreet sethi

Joined: Aug 03, 2009
Posts: 27

I agree with Amit. I have used Java JSON API for generating response for DMOZ API ( and it works great and very easy to use.

I agree. Here's the link:
subject: Getting message as Invalid JSON
It's not a secret anymore!