3

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

Thanks

1
  • 3
    See this question about which Java JSON libraries to use. Commented Dec 17, 2010 at 4:20

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have also used StringTree's JSON easily with no issues. www.stringtree.org/stringtree-json.html
Jackson is a popular alternative to GSON. The APIs are quite similar.
0

I would use JSONObject class:

http://www.json.org/javadoc/org/json/JSONObject.html

or you can build the string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.