SQL SERVER – Fix Error Msg 13603 working with JSON documents

SQL SERVER - Fix Error Msg 13603 working with JSON documents jsonimage-800x800 Working with new data types is something we need to evolve. In this blog, I have written on a number of articles on JSON which you can take a look at. I wanted to write about some of the interesting errors one will get when using JSON custom paths. This is something I stumbled accidentally when using JSON constructs. Let us see how to fix error 13603 while working with JSON documents.

Not everytime the defaults will work when working with databases like SQL Server. You will want to do your own customization and there would be multiple learnings of using the same. Here is a classic example. When working with the FOR JSON PATH, I got the below error:

Msg 13603, Level 16, State 1, Line 1
Property ‘.SQLAuth’ cannot be generated in JSON output due to invalid character in the column name or alias. Column name or alias that contains ‘..’, starts or ends with ‘.’ is not allowed in query that has FOR JSON clause.

This error was generated by the following command shown in the image below:

This is when I realized the mistake I had made. An error is reported when illegal characters are found in the column or column alias used in FOR JSON PATH. The name of one of the column starts or ends with dot.

Remedy: as a corrective action, I fixed column alias to conform to FOR JSON PATH rules.

I wanted to see what the error would be using the same mistake with XML PATH. I wrote the same query as shown:

SELECT 1 as '.SQLAuth',2 as 'SQLAuth..Pinal'

Msg 6850, Level 16, State 1, Line 1
Column name ‘.SQLAuth’ contains an invalid XML identifier as required by FOR XML; ‘.'(0x002E) is the first character at fault.

I can surely see it is similar but slightly different. I am not sure if Microsoft will change this to something similar to JSON error message. But this is good enough in my opinion.

Reference: Pinal Dave (https://blog.sqlauthority.com)

JSON, SQL Error Messages, SQL Scripts, SQL Server
Previous Post
dbForge Studio for SQL Server – Ultimate SQL Server Manager Tool from Devart
Next Post
SQL SERVER – Installation Error – [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Related Posts

1 Comment. Leave new

  • Interesting – I had previously been using XML for some web scraping projects that I have going, largely because of the ability to process illegal characters. I’m going to look through your recent posts Pinal to have a good look to see if I should make the switch to JSON. I prefer JSON to XML, and as long as SQL Server can handle everything I throw at her I will be happy.


Leave a Reply