Posted In: JSON

Convert json string to pretty print json output using JSON library

    1. Example will use following Test data   2. Using GSON.toJson   3. Using Jackson 2X writerWithDefaultPrettyPrinter   4. Using Jackson 1X writerWithDefaultPrettyPrinter   5. Using org.json.JSONObject.toString(indent) from org.json library   6. Using net.sf.json.JSONObject.toString(indent) from net.sf.json-lib library   7. Output { “portfolio” : [ { “stock” : “Infosys”, “quantity” : “100”, “buy” : […]

Read More

Tags: , , , , ,

by , on February 26th, 2017

Posted In: JSON

Are escaping special characters in JSON string required?

  Following tests with various libraries confirms that JSON library will handle special characters and there is no need to use StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml or java.net.URLEncoder   1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using com.jsoniter.output.JsonStream from json iterator library […]

Read More

Tags: , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to parse JSON to POJO in Java

  This example uses general JSONObject or Any object provided by library. To parse JSON to your own application POJO refere this.   1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using JsonIterator from json iterator library   6. Using […]

Read More

Tags: , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to parse JSON in Java – Without POJO

  This example uses general JSONObject or Any object provided by library. To parse JSON to your own application POJO refer how-to-parse-json-to-pojo-in-java   1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using JsonIterator from json iterator library   6. Using […]

Read More

Tags: , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to convert ArrayList to JSON object in Java

  1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using com.jsoniter.output.JsonStream from json iterator library   6. Using net.sf.json.JSONArrayfrom net.sf.json-lib library   7. Using javax.json.JsonArray, javax.json.JsonArrayBuilder from javax.json library   8. Using org.json.JSONArray from org.json library   9. Output [“val1″,”val2″,”val3″,”val4″,”val5”] […]

Read More

Tags: , , , , , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to convert hashmap to JSON object in Java

  1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using com.jsoniter.output.JsonStream from json iterator library   6. Using net.sf.json.JSONObject from net.sf.json-lib library   7. Using javax.json.JsonObject, javax.json.JsonObjectBuilder from javax.json library   8. Using org.json.JSONObject from org.json library   9. Output […]

Read More

Tags: , , , , , , , , ,

by , on February 21st, 2017

  • Categories