1. /**
  2. * Imports and processes JSON data for scheduled runs.
  3. *
  4. * @param {string} jsonString The JSON string containing the scheduled run data.
  5. * @returns {Array<object>|null} An array of objects representing the scheduled runs,
  6. * or null if the JSON is invalid.
  7. */
  8. function importScheduledRuns(jsonString) {
  9. try {
  10. const data = JSON.parse(jsonString); // Parse the JSON string into a JavaScript object
  11. if (!Array.isArray(data)) {
  12. console.error("JSON data must be an array."); // Log error if not an array
  13. return null;
  14. }
  15. return data;
  16. } catch (error) {
  17. console.error("Invalid JSON:", error); // Log error if JSON is invalid
  18. return null;
  19. }
  20. }
  21. // Example usage (replace with your actual JSON data):
  22. // const jsonData = `[{"name": "Backup Database", "time": "03:00", "command": "backup.sh"}, {"name": "Send Report", "time": "08:00", "command": "send_report.py"}]`;
  23. // const scheduledRuns = importScheduledRuns(jsonData);
  24. // if (scheduledRuns) {
  25. // console.log("Scheduled Runs:", scheduledRuns);
  26. // }

Add your comment