Search code examples
jsonsql-serversql-server-2014

For JSON Query error


I am trying to use the 'For JSON PATH'/'For JSON AUTO' in my query to see the output and I am geetting 'Incorrect syntax near JSON' error. Below is my code:

    SELECT TOP 5   
       recid As Id,  
       FirstName, LastName,  
       status As 'Info.status',  
       state As 'Info.state'  
   FROM dbo.Consumers
   FOR JSON PATH

Any help will be greatly appreciated!


Solution

  • JSON in SQL Server is only supported in versions 2016 and later. Your installation is a 2014 install so it will not work. You can either upgrade your installation to SQL Server 2016 or look up custom JSON solutions/functions/procs that others have written.