Skip to content

raghavendar-ts/jsonutil-orgjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JSONUtil for org.json

Maven Central javadoc

A lightweight helper/wrapper library for org.json
to safely extract values from JSONObject and JSONArray without repetitive null checks.


Installation

Add the dependency to your project:

Maven

<dependency>
  <groupId>io.github.raghavendar-ts</groupId>
  <artifactId>jsonutil-orgjson</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

implementation 'io.github.raghavendar-ts:jsonutil-orgjson:1.0.0'

Gradle (Kotlin DSL)

implementation("io.github.raghavendar-ts:jsonutil-orgjson:1.0.0")

Usage

import org.json.JSONObject;
import io.github.raghavendarts.jsonutil.JSONUtil;

public class Example {
    public static void main(String[] args) {
        JSONObject obj = new JSONObject();
        obj.put("id", 101);
        obj.put("name", "Raghavendar");
        obj.put("active", true);

        // Safe extraction
        Integer id = JSONUtil.getInteger(obj, "id");        // 101
        String name = JSONUtil.getString(obj, "name");      // "Raghavendar"
        Boolean active = JSONUtil.getBoolean(obj, "active");// true
        String email = JSONUtil.getString(obj, "email");    // "" (default safe value)

        System.out.println(id + ", " + name + ", " + active + ", " + email);
    }
}

Features

  • Avoids repetitive null and JSONException checks.
  • Provides safe defaults ("", 0, false, empty JSONObject/JSONArray).
  • Works as a wrapper on top of the popular org.json library.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Author

Raghavendar T S

GitHub: @raghavendar-ts

LinkedIn: Raghavendar T S

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages