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

Parse JSON file with servlet

Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

Hello All,

I am trying to parse a JSON file inside a servlet. Can you tell me how do i get started. The sample of JSON file is as below:-

{ items: [
label: "Setting up the Environment for CI",
id: "1",
message: "Dojo is available under *either* the terms of the modified BSD " +
"license *or* the Academic Free License version",

If i want to get the value of the message property in the JSON file, how do i get that? Also can you point to Servlet+JSON tutorials.

Sean Clark

Joined: Jul 15, 2009
Posts: 377


I recommend you don't try to do this yourself and use a java library that exists already for this. I've used the one from the site and it would be more than useable in your situation.


I love this place!
Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

Thanks Sean,

Can you get me started on this with a small example. I can pick from there.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63529

An example is only possible if you pick one of the libraries. Personally, I've been using Google's Gson library.

By the way, most of these libraries will require strictly valid JSON as input; which your example is not.

[Asking smart questions] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32793

I've also been using GSON because it is so simple.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Parse JSON file with servlet
It's not a secret anymore!