import isObject from '../.internal/isObject' /** * @module utils */ /** * @name parseJSON * @static * * @description * JSON String 값을 JSON 객체로 변환하여 반환 * * @param {String} jsonValue * @param {Object} defaultValue * **/ function parseJSON(jsonValue: string | Object, defaultValue: Object = {} ) : Object { if (jsonValue === 'null' || jsonValue === null || typeof jsonValue === 'undefined') { return defaultValue } var result = jsonValue && isObject(jsonValue) ? jsonValue : defaultValue if (jsonValue && typeof jsonValue === 'string') { try { result = JSON.parse(jsonValue as string) } catch (e) { // console.error("parseJSON Error: ", e, jsonString) result = defaultValue } } return result } export default parseJSON