Hi, I have trouble understanding JSON_QUERY and JS...
# troubleshooting
c
Hi, I have trouble understanding JSON_QUERY and JSON_VALUE. I have a json {"model_results":[{"name":"add_card_v3","score":0.06742525,"threshold":0.5},{"name":"add_card_v3_rsm","score":0.06742525,"threshold":0.5"... I want to extract the score of the model with the name
add_card_v3_rsm
so my json path is
"""$.model_results[?(@.name=="add_card_v3_rsm")].score"""
when I do
Copy code
SELECT JSON_Query('$json', '$jsonPath') as json_extract
I get
[ 0.06742525]
as a result. but since the score is a scalar and I want to use it as such, I would like to use JSON_VALUE . but when I run the same jsonpath in JSON_VALUE i get
null
as result? I thought this is the point of this function
t
JSON_VALUE
is used to extract a single, simple value and doesn't support complex queries with conditions. Since your JSON path includes a filter (
[?(@.name=="add_card_v3_rsm")]
),
JSON_VALUE
returns null because it can't process the filter.
JSON_QUERY
can handle complex structures like arrays or objects, which is why it works but gives you an array. To get a scalar value with a condition, you might need a more advanced query technique specific to your SQL system, like using
CROSS APPLY
in SQL Server or equivalent functions in other databases.
c
ok understood, thanks