parseJson(jsonString: string, options?: JsonParseOptions): any | any[]
A wrapper around JSON.parse() with some extra features.
If you prefer undefined to be returned when a JSON parsing error occurs, instead of an
error being thrown, then pass the option { silent: true }.
Further to that, when doing a regular JSON.parse(), neither JSON.parse(false) nor
JSON.parse(1234) will result in errors. If you prefer a stricter JSON parse, which would
treat those as errors, therefore always expecting either objects or an array of values/objects,
then pass the option { strict: true }.
Both options can be used, depending on whether you want a strict parse, and/or an error to be
thrown, as opposed to undefined being returned for a parse failure.
Returns
Returns the parsed JSON object or array of objects/values
A wrapper around
JSON.parse()
with some extra features.If you prefer
undefined
to be returned when a JSON parsing error occurs, instead of an error being thrown, then pass the option{ silent: true }
.Further to that, when doing a regular
JSON.parse()
, neitherJSON.parse(false)
norJSON.parse(1234)
will result in errors. If you prefer a stricter JSON parse, which would treat those as errors, therefore always expecting either objects or an array of values/objects, then pass the option{ strict: true }
.Both options can be used, depending on whether you want a strict parse, and/or an error to be thrown, as opposed to
undefined
being returned for a parse failure.Returns
Returns the parsed JSON object or array of objects/values