Skip to content

JSON_QUERY

  • jsondata: This is the field or expression that returns the JSON text to be parsed. The JSON_QUERY function extracts an object or an array from a JSON string.
  • expression: This is a JSON path expression that specifies the object or the array to extract from the JSON text. The expression begins with a $. In case the expression returns a scalar value, JSON_QUERY returns null.
DECLARE @json NVARCHAR(4000) = N'
{
"info": {
"type": "Fruit",
"color": "Red",
"isTrue": true,
"nothing": null
}
}';
SELECT JSON_QUERY(@json, '$.info')
{
"type": "Fruit",
"color": "Red",
"isTrue": true,
"nothing": null
}

In the JSON_QUERY example above, SQL query is declaring a JSON object and querying it using the $.info path. This returns the JSON part of the object that is the value of the ‘info’ key.