• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to properly implement JSON in Java code?

 
Ranch Hand
Posts: 76
IntelliJ IDE Spring BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76
IntelliJ IDE Spring BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76
IntelliJ IDE Spring BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1043
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Json simple" works great for me.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, Ivan Jozsef Balazs why you think Json simple is better than Jackson?
 
reply
    Bookmark Topic Watch Topic
  • New Topic