UNPKG

@mikezimm/fps-library-v2

Version:

Library of reusable typescript/javascript functions, interfaces and constants

16 lines 600 B
export function formatJSONString(jsonString) { // Added to avoid error when empty string: Invalid JSON string: SyntaxError: Unexpected end of JSON input if (!jsonString) return ''; try { // const jsonObject = JSON.parse( jsonString.replace( lineFeedRegex, '' ) ); // return [ true, jsonString ]; const jsonObject = JSON.parse(jsonString); return JSON.stringify(jsonObject, null, 2); } catch (e) { console.log('Invalid JSON string:', e); return jsonString; } } //# sourceMappingURL=formatJSONString.js.map