mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 04:20:05 +00:00
fix: handle the case when array is passed in getValidJson method
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
/**
|
||||
* Checks if string is in valid JSON format else throw error.
|
||||
* if string passed then parse the string to json else if throw error for all other types unless it is not a valid json object.
|
||||
* @param str - string to check.
|
||||
*/
|
||||
export const getValidJson = (str: string | object) => {
|
||||
try {
|
||||
if (Array.isArray(str)) {
|
||||
throw new Error('Can not parse array object to json.')
|
||||
}
|
||||
if (typeof str === 'object') return str
|
||||
|
||||
return JSON.parse(str)
|
||||
|
||||
Reference in New Issue
Block a user