I was hoping to take advantage of $..
in json_value()
function within TSQL queries using stored json
documents. Unfortunately it doesn't work:
JSON path is not properly formatted. Unexpected character '.' is found at position 2.
and according to documentation, there was even no intention to:
Path steps can contain the following elements and operators.
Key names. For example, $.name and $."first name". If the key name starts with a dollar sign or contains special characters such as spaces, surround it with quotes.
Array elements. For example, $.product[3]. Arrays are zero-based.
The dot operator (.) indicates a member of an object. For example, in $.people1.surname, surname is a child of people.
Is there any other method, how to find the attribute a
at any level(s) in structured json
stored in a TSQL table column?
For example, let's have a
on arbitrary level in the json
document:
select json_value(json, '$..a') from data
would return both values (thus 1, 2
) for following values in data.json
column:
first:
{
"a": 1
}
second:
{
"b": {
"a": 2
}
}