import org.json.JSONArray;
import org.json.JSONObject;
public class JsonDryRun {
public static void main(String[] args) {
// Example JSON objects for dry-run scenarios
JSONObject user1 = new JSONObject();
user1.put("id", 123); // User ID
user1.put("name", "Alice"); // User's name
user1.put("email", "alice@example.com"); // User's email address
user1.put("isActive", true); // User's active status
JSONObject product1 = new JSONObject();
product1.put("productId", "P1001"); // Product ID
product1.put("name", "Laptop"); // Product name
product1.put("price", 1200.00); // Product price
product1.put("category", "Electronics"); // Product category
JSONArray tags = new JSONArray(); // Array of tags
tags.put("laptop");
tags.put("computer");
product1.put("tags", tags);
JSONObject order1 = new JSONObject();
order1.put("orderId", "O4567"); // Order ID
order1.put("userId", 123); // User ID associated with the order
order1.put("orderDate", "2024-01-26"); // Order date
JSONArray items = new JSONArray(); // Array of items in the order
JSONObject item1 = new JSONObject();
item1.put("productId", "P1001");
item1.put("quantity", 1);
items.put(item1);
JSONObject item2 = new JSONObject();
item2.put("productId", "P1002");
item2.put("quantity", 2);
items.put(item2);
order1.put("items", items);
// Print the JSON objects (for demonstration)
System.out.println("User 1: " + user1.toString(2)); // Pretty print with indentation
System.out.println("Product 1: " + product1.toString(2));
System.out.println("Order 1: " + order1.toString(2));
}
}
Add your comment