/**
* Imports and processes JSON data for scheduled runs.
*
* @param {string} jsonString The JSON string containing the scheduled run data.
* @returns {Array<object>|null} An array of objects representing the scheduled runs,
* or null if the JSON is invalid.
*/
function importScheduledRuns(jsonString) {
try {
const data = JSON.parse(jsonString); // Parse the JSON string into a JavaScript object
if (!Array.isArray(data)) {
console.error("JSON data must be an array."); // Log error if not an array
return null;
}
return data;
} catch (error) {
console.error("Invalid JSON:", error); // Log error if JSON is invalid
return null;
}
}
// Example usage (replace with your actual JSON data):
// const jsonData = `[{"name": "Backup Database", "time": "03:00", "command": "backup.sh"}, {"name": "Send Report", "time": "08:00", "command": "send_report.py"}]`;
// const scheduledRuns = importScheduledRuns(jsonData);
// if (scheduledRuns) {
// console.log("Scheduled Runs:", scheduledRuns);
// }
Add your comment