@synotech/utils
Version:
a collection of utilities for internal use
20 lines (19 loc) • 449 B
text/typescript
/**
* This function returns a well structured json object
* @module toJSON
* @param {string} object - a stringified object in string format
* @return {object} {Object} a well structured json object
* @example
*
* toJSON('{"name":"John Doe"}') // returns {"name": "John Doe"}
*
*/
export const toJSON = (object: any): any => {
let json;
try {
json = JSON.parse(JSON.stringify(object));
} catch (e) {
json = null;
}
return json;
};