Skip to content
Advertisement

JSON_VALUE value returning NULL instead of actual value

I have table in that one column contains jsonstring.While trying to read value from json result coming as NULL instead of name value. query:

Result:

NullResult

Why and How to solve this?

Thanks.

Advertisement

Answer

I would personally suggest using OPENJSON with a WITH clause:

As for why you got NULL, that’s covered in the documentation:

Return value

Returns a single text value of type nvarchar(4000). The collation of the returned value is the same as the collation of the input expression.

If the value is greater than 4000 characters:

  • In lax mode, JSON_VALUE returns null.
  • In strict mode, JSON_VALUE returns an error.

If you have to return scalar values greater than 4000 characters, use OPENJSON instead of JSON_VALUE. For more info, see OPENJSON (Transact-SQL).

I’ve added emphasis to the relevant part. The value of [name] in your example is 14322 characters; well over 4000. As you can see, the documentation also recommends the method I used.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement