Home > OS >  The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal
The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal

Time:11-17

I am passing this JSON to a stored procedure in SQL Server

{
    "individual": [
        {
            "app_id": 1057029,
            "size": 2
        },
        {
            "app_id": 1057053,
            "size": 3
        },
        {
            "app_id": 1057048,
            "size": 1
        }
    ]
}

In the stored procedure I am extracting values of app_id and size as under

SET @len = JSON_VALUE(@json, CONCAT('$.individual[', @i, '].size'));
SET @appId = JSON_VALUE(@json, CONCAT('$.individual[', @i, '].app_id'));

(Here i is index variable incrementing in a loop)

This works perfect on Microsoft SQL Server 2017 (version 14.0.1000.169)

But on Microsoft SQL Server 2016 (version 13.0.4604.0) I am getting error:

JSON_Value error: The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal

Please note this is not duplicate as I already have referred questions below on SO but still didn't get solution.

enter image description here

  • Related