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: GSON, JSON

Check two JSON Objects for equality – GSON

  This example uses GSON library     Examples using GSON   1. Success test with a JSON string   2. Error test with a JSON string   3. Success test with a JSON string This test covers How do I compare 2 json files having same key-values but in different order in java?  

Read More

Tags: , ,

by , on February 24th, 2017

Posted In: JSON

Check two JSON Objects for equality – Jackson

  This example uses jackson library     Examples using Hamcrest-JSON   1. Success test with a JSON string   2. Error test with a JSON string   3. Success test with a JSON String This test covers How do I compare 2 json files having same key-values but in different order in java?   […]

Read More

Tags: , ,

by , on February 24th, 2017

Posted In: JSON

Check two JSON Objects for equality – Hamcrest-JSON

  This example uses hamcrest-json library     Examples using Hamcrest-JSON   1. Success test with a org.json.JSONObject   2. Error test with a org.json.JSONObject   3. Success test with a JSON String   4. Error test with a JSON String  

Read More

Tags: , , ,

by , on February 24th, 2017

Posted In: JSON

How to transform JSON to another JSON format using JOLT

  This example uses JOLT library   You need input json and spec json   It has following Transforms shift : copy data from the input tree and put it the output tree default : apply default values to the tree remove : remove data from the tree sort : sort the Map key values […]

Read More

Tags: , ,

by , on February 24th, 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