• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to properly implement JSON in Java code?  RSS feed

 
Ranch Hand
Posts: 71
BSD IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attempting to parse a text file that contains JSON and after seeing over twenty libraries and none that are native, I'm wondering waht is the best practices for implementing JSON parsing, be it text files, online API responses, or what have you?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean "none that are native"? What requirement do you have that's not being met?

A quick google serch for java json library turned up several options. What's wrong with those?
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used gson in the past and was quite happy with it. You can find it via the link Jeff provided
 
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not to use JAXB to map Java Objects to JSON via Jackson implementation? I used it before and it works great.
 
Chris Creed
Ranch Hand
Posts: 71
BSD IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:What do you mean "none that are native"?


Perhaps I'm using the wrong term. What I mean is that I can't type in say JSONParser parser = new JSONParser(); into Eclipse an it'll say "hey you're missing java.io.JSONParser. Want me to add that for you?", but instead it seems that a 3rd party choice is needed to be added. I guess what I'm after is out of the plethora of options out there, which ones would be considered industry standard?
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no support for JSON in Java's standard API, so you'll have to use a third-party library.

In the future there's probably going to be support (in Java EE 7); it's under development in JSR-353. See Java API for JSON Processing (JSR-353).
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Creed wrote:
Jeff Verdegan wrote:What do you mean "none that are native"?


Perhaps I'm using the wrong term. What I mean is that I can't type in say JSONParser parser = new JSONParser(); into Eclipse an it'll say "hey you're missing java.io.JSONParser. Want me to add that for you?", but instead it seems that a 3rd party choice is needed to be added.


Ah, okay. What you mean then is that it's not in the core API.

I guess what I'm after is out of the plethora of options out there, which ones would be considered industry standard?


I don't believe one has emerged as the de facto standard yet. Your best be it probably to do a Google search and see what people are saying about the various options, pick 2 or 3 candidates, and see how they work for you.
 
Chris Creed
Ranch Hand
Posts: 71
BSD IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Chris Creed wrote:
Jeff Verdegan wrote:What do you mean "none that are native"?


Perhaps I'm using the wrong term. What I mean is that I can't type in say JSONParser parser = new JSONParser(); into Eclipse an it'll say "hey you're missing java.io.JSONParser. Want me to add that for you?", but instead it seems that a 3rd party choice is needed to be added.


Ah, okay. What you mean then is that it's not in the core API.

I guess what I'm after is out of the plethora of options out there, which ones would be considered industry standard?


I don't believe one has emerged as the de facto standard yet. Your best be it probably to do a Google search and see what people are saying about the various options, pick 2 or 3 candidates, and see how they work for you.


Seems there's about five that I found tutorials and postings for on stackoverflow, and they all seem to be broken in various amounts. Incredible that a language like PHP can parse JSON easier then Java can, really needs to have something standardized. maybe in v8
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Creed wrote:
Seems there's about five that I found tutorials and postings for on stackoverflow, and they all seem to be broken in various amounts. Incredible that a language like PHP can parse JSON easier then Java can, really needs to have something standardized. maybe in v8

PHP is overall easier, especially when you opt out from OOP, but you will have problems with building and maintaining big complex systems.
 
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Json simple" works great for me.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Jozsef Balazs wrote:"Json simple" works great for me.

Why not Jackson, it look like a de-facto standard. Can "Json simple" be mapped to Java Objects via JAXB?
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, Ivan Jozsef Balazs why you think Json simple is better than Jackson?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!