JSON Articles

Page 7 of 16

Convert JSON to/from Map using Jackson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 3K+ Views

JSON is a format that is used to exchange data between a server and a client. It is lightweight and easy to read and write. In Java, we can convert JSON to/from Map using various libraries. In this article, we will discuss how to convert JSON to/from Map using the Jackson library. The Jackson is a library for Java, and it has very powerful data binding capabilities and provides a framework to serialize custom java objects to JSON and deserialize JSON back to Java object. We can convert JSON to/from Map using readValue() and writeValueAsString() methods of com.fasterxml.jackson.databind.ObjectMapper class. To ...

Read More

How to format a date using the Gson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 7K+ Views

Gson is a JSON for Java, which is developed by Google. We can format a date using the Gson library in Java. The Gson library provides a GsonBuilder class that allows us to create a Gson instance with custom settings. We call the create() method of the GsonBuilder class to create an instance of the Gson class. Then we use the method setDateFormat() to configure Gson to serialize Date objects according to the pattern provided. In order to use the Gson library, we need to add it to our project. If you are using Maven, add this to your ...

Read More

Importance of a JSONTokener in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 2K+ Views

If you have ever worked with JSON in Java, you might have used classes like JSONObject, JSONArray, JsonParser, etc. These classes are part of the org.json library. We use these classes to build JSON or parse JSON. But behind the scenes, these classes use a class called JSONTokener. In this article, we will learn about the JSONTokener class and its importance in Java. What is JSONTokener? The JSONTokener class is like a tool that reads a JSON string step by step, breaking it into smaller parts called tokens. It is like a helper that makes it easier to understand and ...

Read More

How to implement custom JSON de-serialization with Gson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 778 Views

Deserialization is the process of converting JSON data back into Java objects. Gson provides a simple way to do this using the fromJson() method. Custom JSON de-serialization with Gson Gson is a Java library developed by Google to convert Java objects into their JSON format and vice versa. Custom JSON is a way we can modify or extend the standard JSON format so that it can suit our specific needs. To use the Gson library, we need to add the Gson library to our project. If you are using Maven, add this to your pom.xml file: com.google.code.gson gson 2.8.9 ...

Read More

How to convert a List to JSON array using the Jackson library in Java?

Manisha Chand
Manisha Chand
Updated on 29-Apr-2025 12K+ Views

JSON is used in Java applications in APIs, file storage, and data communication between systems. Sometimes, we need to convert a list into a JSON array. In this article, we will learn how to convert a list to JSON array using the Jackson library. Jackson Library It is a library that is used in Java to work with JSON data. It provides APIs to serialize Java objects into JSON and deserialize JSON back into Java objects. If you want to read more about the Jackson library, you can refer Jackson library. There are mainly three components of Jackson - ...

Read More

How to get all the keys of a JSON object using GSON in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 22-Apr-2025 4K+ Views

JSON is the data interchange format that stores values in key-value pairs. (To learn more about JSON, you can refer to the JSON tutorial). So, as we have key and value in JSON, we will try to get all those keys using the Gson library. Gson Library: Retrieving all the keys of a JSON Gson is a third-party Java library developed by Google. It is used for converting Java objects to JSON and vice versa. To know more about Gson, refer to the Gson tutorial. We can use the keySet() method of JsonObject class to get all the keys of a ...

Read More

How can we parse a nested JSON object in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 22-Apr-2025 16K+ Views

Sometimes, we need to parse a nested JSON object, which means an object inside another object. In this article, let's learn about how to parse a nested JSON object in Java. If you don't know about JSON, refer JSON overview. Parsing a Nested JSON Object in Java? We can achieve this using some of the popular Java libraries. Those are listed below: Using org.json library : We will use jsonObject.getJSONObject method to parse a nested JSON object. Using Gson library : We will use JsonParser.parseString(json).getAsJsonObject(). Using Jackson library : In this, We will use ObjectMapper.readTree(json) method. Now, ...

Read More

How can we sort a JSONArray in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 22-Apr-2025 10K+ Views

In this article, we will learn how to sort a JSON array in Java. But first, let’s understand what JSON is. If you do not have knowledge about JSON, you can refer to the tutorial JSON Overview. Now, let's see different ways to sort a JSON array in Java. Ways to sort a JSON array in Java Following are different ways to sort a JSON array in Java - Sort JSON array Without any Dependency Using org.json library: Methods are getJSONArray() and getJSONObject() Using Gson library: Methods ...

Read More

How to get the values of the different types from a JSON object in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 22-Apr-2025 31K+ Views

We often need to extract values from a JSON object. In this article, we will learn how to get the values of the different types from a JSON object in Java. What is JSONObject? Java JSONObject is a class in the org.json package that represents a JSON object. Refer JSONObject for more information. Let's see the steps to get the values of different types from a JSON object in Java. Getting different values from a JSON object Before we start, let's add the required library to our program. We can add a .jar file, or we can use a Maven ...

Read More

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

Aishwarya Naglot
Aishwarya Naglot
Updated on 22-Apr-2025 4K+ Views

Converting a map to a JSON object is our task here. Let's see how to convert a map to a JSON object in Java using the Gson library. Converting a Map to JSON using the Gson library JSON is a simple and lightweight data interchange format. It stores data in key-value pairs. A map is also a collection of key-value pairs. So, we can easily convert a map to a JSON object. If you are not familiar with JSON, refer JSON. And if you want to know more about Map, refer Map. Gson is developed by Google. It is an ...

Read More
Showing 61–70 of 152 articles
« Prev 1 5 6 7 8 9 16 Next »
Advertisements