@kaelyx/ts-kit / string / isJson
Function: isJson()
isJson(
input):boolean
Defined in: string/is-json/is-json.ts:23
isJson checks if a string is valid JSON and returns a boolean result. use parseJson internally to determine if the string is valid JSON. use parseJson if you want the parsed result instead of just a boolean.
Parameters
input
string
The string to check.
Returns
boolean
A boolean indicating whether the string is valid JSON.
Example
ts
isJson('{"name": "John"}') // true
isJson('not json') // false
isJson('42') // true
isJson("{'name': 'John'}") // false
isJson('') // false