goldies
    Preparing search index...

    Function isJSON

    • Safely verifies input argument is valid JSON.

      Parameters

      • data: any

        The data to check if it is valid JSON.

      Returns boolean

      • A boolean indicating if the data is valid JSON or not.
      const validJSON = '{"name": "John", "age": 30}'
      const invalidJSON = '{name: "John", age: 30}'

      console.log(isJSON(validJSON)) // true
      console.log(isJSON(invalidJSON)) // false