Skip to content

JSON_VALUE

  • expression: This parameter refers to the JSON text, which is an expression. It can also be a column that has JSON text.
  • path: This parameter signifies the path to the value in the JSON text. The path string, which uses JavaScript-like syntax, identifies the value that needs to be extracted.
DECLARE @json NVARCHAR(4000) = N'{
"info": {
"type": "Fruit",
"name": "Apple",
"color": "Green"
}
}';
SELECT JSON_VALUE(@json, '$.info.color') as fruit_color;
fruit_color
Green

In the provided SQL query, the JSON_VALUE function is used to extract a value from a JSON string. The value extracted is specified by the JSON path $.info.color. This path navigates to the “info” object inside the JSON string, then retrieves the value of “color”, which is “Green”. The result is returned in the column named “fruit_color”.