Working with JSON payloads in Java backend applications is performed using standard libraries like org.json or Jackson ObjectMapper.

Java JSONObject Creation & Parsing Example

JsonExample.javajava
import org.json.JSONObject;
 
public class JsonExample {
    public static void main(String[] args) {
        // 1. Create JSON Object dynamically
        JSONObject json = new JSONObject();
        json.put("status", "success");
        json.put("code", 200);
        json.put("user", "lynxbeedev");
 
        System.out.println("JSON Output: " + json.toString());
 
        // 2. Parse values out of JSON string
        String rawJson = "{"title":"Java Guide","views":1500}";
        JSONObject parsed = new JSONObject(rawJson);
        String title = parsed.getString("title");
        int views = parsed.getInt("views");
        
        System.out.println("Title: " + title + ", Views: " + views);
    }
}