Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a JSON document using Java?

Tags:

java

json

I want to read data from the database, convert it to docs (JSON) using Java.

Thanks

like image 537
Sameek Mishra Avatar asked Mar 12 '26 14:03

Sameek Mishra


1 Answers

GSON is a Java library from Google to convert Java objects to JSON. You can simply pass a Java object to the library function and it will return a JSON string.

Download: http://code.google.com/p/google-gson/

Example: http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/

I have used the library from http://www.json.org, but the whole thing seems to be tedious to me. GSON is simple to use IMHO.