Files
hoppscotch/packages/hoppscotch-app/helpers/functional/json.ts
2022-04-18 19:29:45 +05:30

13 lines
409 B
TypeScript

import * as O from "fp-ts/Option"
/**
* Checks and Parses JSON string
* @param str Raw JSON data to be parsed
* @returns Option type with some(JSON data) or none
*/
export const safeParseJSON = (str: string): O.Option<object> =>
O.tryCatch(() => JSON.parse(str))
export const prettyPrintStringifyJSON = (jsonObject: any): O.Option<string> =>
O.tryCatch(() => JSON.stringify(jsonObject, null, "\t"))