T-SQL Tutorial

SQL Server ISJSON


The SQL Server ISJSON function is a built-in function that is used to determine whether a string contains valid JSON (JavaScript Object Notation) syntax. JSON is a lightweight data interchange format that is commonly used to transmit data between applications.

The ISJSON function takes a string parameter as input and returns a bit value that indicates whether the input string is a valid JSON format or not. If the input string is valid JSON, the function returns 1, otherwise, it returns 0.


Syntax

Here's the syntax of the SQL Server ISJSON function:

ISJSON ( expression )

The expression parameter is the string value that you want to check for JSON syntax. It can be a column name, a variable, or a literal string value.


Example

Here's an example of how to use the SQL Server ISJSON function:

SELECT ISJSON('{ "name": "John", "age": 30, "city": "New York" }') AS IsJson

In this example, the ISJSON function is used to check whether the input string contains valid JSON syntax. The function returns 1, indicating that the input string is valid JSON.

If the input string is not valid JSON, the function will return 0. Here's an example:

SELECT ISJSON('This is not a valid JSON string') AS IsJson

In this example, the ISJSON function returns 0, indicating that the input string is not valid JSON.

In summary, the SQL Server ISJSON function is a useful tool for verifying whether a string contains valid JSON syntax. By using this function, you can ensure that your JSON data is well-formed and avoid errors when working with JSON data in SQL Server.