- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we check if a JSON object is empty or not in Java?
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 example
Example
import java.util.*; import org.json.*; public class JSONObjectTest { public static void main(String[] args) { JSONObject jsonObj = new JSONObject( "{" + "Name : Jai," + "Age : 25, " + "Salary: 25000.00 " + "}" ); if(jsonObj.isEmpty()) { System.out.println("JSON is empty"); } else { System.out.println("JSON is not empty"); } } }
Output
JSON is not empty
Advertisements