1.0.2 • Published 2 years ago

@architecturex/utils.isjson v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@architecturex/utils.isjson

isJSON(str: string): boolean

The isJSON function checks if a provided string is a valid JSON string. This can be particularly useful in scenarios where you receive data as strings and need to determine if they can be safely parsed as JSON.

Installation

npm install @architecturex/utils.isjson

Usage

import isJSON from '@architecturex/utils.isjson'

const data = '{"name": "John", "age": 30}'

if (isJSON(data)) {
  console.log('Valid JSON string!')
} else {
  console.log('Not a JSON string')
}

Common Use Cases

  • Validating incoming data in API endpoints
  • Safe JSON parsing in applications to prevent runtime errors
  • Checking user input in forms where JSON strings might be provided

Contribution

Feel free to suggest improvements, report issues, or contribute to enhancing this utility. Your feedback and contributions are welcome!