UNPKG

quantique-converter

Version:
17 lines (16 loc) 434 B
// Convert to JSON const convertToJson = (input) => { if (typeof input === 'string') { try { return { isValid: true, error: '', convertedValue: JSON.parse(input) }; } catch (e) { return { isValid: false, error: 'Invalid JSON string', convertedValue: null, }; } } return { isValid: true, error: '', convertedValue: input }; }; module.exports = convertToJson;