1. import org.json.JSONArray;
  2. import org.json.JSONObject;
  3. public class JsonDryRun {
  4. public static void main(String[] args) {
  5. // Example JSON objects for dry-run scenarios
  6. JSONObject user1 = new JSONObject();
  7. user1.put("id", 123); // User ID
  8. user1.put("name", "Alice"); // User's name
  9. user1.put("email", "alice@example.com"); // User's email address
  10. user1.put("isActive", true); // User's active status
  11. JSONObject product1 = new JSONObject();
  12. product1.put("productId", "P1001"); // Product ID
  13. product1.put("name", "Laptop"); // Product name
  14. product1.put("price", 1200.00); // Product price
  15. product1.put("category", "Electronics"); // Product category
  16. JSONArray tags = new JSONArray(); // Array of tags
  17. tags.put("laptop");
  18. tags.put("computer");
  19. product1.put("tags", tags);
  20. JSONObject order1 = new JSONObject();
  21. order1.put("orderId", "O4567"); // Order ID
  22. order1.put("userId", 123); // User ID associated with the order
  23. order1.put("orderDate", "2024-01-26"); // Order date
  24. JSONArray items = new JSONArray(); // Array of items in the order
  25. JSONObject item1 = new JSONObject();
  26. item1.put("productId", "P1001");
  27. item1.put("quantity", 1);
  28. items.put(item1);
  29. JSONObject item2 = new JSONObject();
  30. item2.put("productId", "P1002");
  31. item2.put("quantity", 2);
  32. items.put(item2);
  33. order1.put("items", items);
  34. // Print the JSON objects (for demonstration)
  35. System.out.println("User 1: " + user1.toString(2)); // Pretty print with indentation
  36. System.out.println("Product 1: " + product1.toString(2));
  37. System.out.println("Order 1: " + order1.toString(2));
  38. }
  39. }

Add your comment