Raja has Published 760 Articles

Convert a Map to JSON using the Gson library in Java?

raja

raja

Updated on 04-Jul-2020 07:19:48

3K+ Views

A Gson is a library that can be used to parse Java objects to JSON and vice-versa. It can also be used to convert a JSON string to an equivalent Java object. In order to parse java object to JSON or JSON to java object, we need to import com.google.gson package ... Read More

Convert a list of objects to JSON using the Gson library in Java?

raja

raja

Updated on 04-Jul-2020 07:14:39

7K+ Views

A Gson is a library that can be used to convert Java Objects to JSON representation. It can also be used to convert a JSON string to an equivalent Java object. The primary class to use is Gson which we can create by calling the new Gson() and the GsonBuilder class can be ... Read More

Convert JSON object to Java object using Gson library in Java?

raja

raja

Updated on 04-Jul-2020 07:03:16

8K+ Views

A Gson is a json library for java, which is created by Google and it can be used to generate a JSON. By using Gson, we can generate JSON and convert JSON to java objects. We can call the fromJson() method of Gson class to convert a JSON object to Java Object.Syntaxpublic fromJson(java.lang.String ... Read More

How can we check if a JSON object is empty or not in Java?

raja

raja

Updated on 04-Jul-2020 06:54:20

8K+ Views

A JSON is a lightweight data-interchange format and the format of JSON is a key with value pair. The JSONObject can parse a text from a String to produce a map-like object and supports java.util.Map interface. We can check whether the JSON object is empty or not in the below exampleExampleimport java.util.*; import org.json.*; ... Read More

How can we sort a JSONArray in Java?

raja

raja

Updated on 04-Jul-2020 06:50:23

7K+ Views

The JSON is one of the widely used data-interchange formats and is a lightweight and language independent. A JSONArray can parse text from a String to produce a vector-like object and supports java.util.List interface. We can sort a JSONArray in the below example.Exampleimport java.util.*; import org.json.*; public class SortJSONArrayTest {    public static void main(String[] args) ... Read More

When can we use a JSONStringer in Java?

raja

raja

Updated on 04-Jul-2020 06:49:30

400 Views

A JSONStringer provides a convenient way of producing JSON text and it can strictly follow to JSON syntax rules. Each instance of JSONStringer can produce one JSON text. A JSONStringer instance provides a value-method for appending values to the text and a key-method for adding keys before values in objects. There is ... Read More

How can we decode a JSON object in Java?

raja

raja

Updated on 04-Jul-2020 06:27:24

2K+ Views

A JSON is a lightweight, text-based and language-independent data exchange format. A JSON can represent two structured types like objects and arrays. We can decode a JSON object using JSONObject and JSONArray from json.simple API. A JSONObject works as a java.util.Map whereas JSONArray works as a java.util.List.In the below example, we can decode a JSON object.Exampleimport org.json.simple.*; import ... Read More

How can we encode a JSON object in Java?

raja

raja

Updated on 04-Jul-2020 05:58:28

2K+ Views

A JSONObject is a subclass of java.util.HashMap where no order is provided. We can also use the strict ordering of elements as well with the help of the JSONValue.toJSONString(map) method i.e. by the implementation of java.util.LinkedHashMap.We can encode a JSON object in the below two examples.Example import java.util.*; import org.json.simple.JSONObject; public class ... Read More

How can we convert a map to the JSON object in Java?

raja

raja

Updated on 04-Jul-2020 05:51:35

9K+ Views

The JSON is a lightweight, text-based and language-independent data exchange format. The JSON can represent two structured types like objects and arrays. An object is an unordered collection of key/value pairs and an array is an ordered sequence of values. We can convert a Map to JSON object using the toJSONString() method(static) of org.json.simple.JSONValue. It has two ... Read More

How can we merge two JSON arrays in Java?

raja

raja

Updated on 04-Jul-2020 05:51:07

6K+ Views

A JSON is a lightweight data-interchange format and the format of JSON is a key with value pair. The JSONArray can parse text from a String to produce a vector-like object and supports java.util.List interface. We can use org.json.simple.JSONArray class to merge two JSON arrays in Java.We can merge two JSON arrays using the ... Read More

Advertisements