JSON_VALUE

The JSON_VALUE function extracts a scalar value from a JSON string. It accepts two input arguments:

  • Expression: This is  JSON text in the Unicode format.
  • Path: This is an optional argument; it is a JSON path expression and you can use it to specify a fragment of the input expression.

The return type of the function is nvarchar(4000), with the same collation as in the input expression. If the extracted value is longer than 4,000 characters, the function returns NULL provided the path is in lax mode, or an error message in the case of strict mode.

If either the expression or the path is not valid, the JSON_VALUE function returns an error explaining that the JSON text is not properly formatted.

The following example shows the

Get Mastering SQL Server 2017 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.