5

I am trying to retrieve values from a json string stored in an sqlserver object using SQL. this is what I have

SELECT JSON_VALUE([JSOn_Field], '$.name')
FROM users

I am getting this error:

Argument data type text is invalid for argument 1 of json_value function.

7
  • 2
    Why are you using Text instead of NVarchar(max)? Commented Aug 8, 2018 at 12:58
  • 5
    You probably need to cast the field: cast([JSOn_Field] as nvarchar(max)) Commented Aug 8, 2018 at 13:03
  • how do I do that inside an sql query? Commented Aug 8, 2018 at 13:07
  • 8
    SELECT JSON_VALUE(cast([JSOn_Field] as nvarchar(max)), '$.name') FROM users Commented Aug 8, 2018 at 13:09
  • Thank you this is great it worked!! Commented Aug 8, 2018 at 13:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.