json.ts 270 B

123456789
  1. import * as O from "fp-ts/Option"
  2. /**
  3. * Checks and Parses JSON string
  4. * @param str Raw JSON data to be parsed
  5. * @returns Option type with some(JSON data) or none
  6. */
  7. export const safeParseJSON = (str: string): O.Option<object> =>
  8. O.tryCatch(() => JSON.parse(str))