quantique-converter
Version:
Converters for all kind of data
17 lines (16 loc) • 434 B
JavaScript
// 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;