SqlScriptDOM icon indicating copy to clipboard operation
SqlScriptDOM copied to clipboard

JSON_OBJECT does not parse inside RETURN statement

Open naveennaik1 opened this issue 2 months ago • 0 comments

Version - 170.128.0

Parser - TSql170Parser

JSON_OBJECT when inside RETURN statement does not get parsed with above mentioned parser version and details.

Steps to reproduce -

Try parsing the below SQL script with the parser:

ALTER FUNCTION FnName
    ()
RETURNS NVARCHAR(MAX)
AS
    BEGIN
        RETURN
        JSON_OBJECT('Authorization' : 'Bearer ' + (SELECT Value1
                                                           FROM   dbo.table1
                                                           WHERE  field1 = 'Token'));
    END;
GO

Example -

    static void Main(string[] args)
    {
        var script = "<Example Script>";
 
        var parser = new TSql170Parser(true, 0);
        var fragment = parser.Parse(new StringReader(script), out var parseErrors);
 
        if (parseErrors.Count > 0)
        {
            Console.WriteLine(parseErrors[0].Message);
        }
    }

Error message :-

Incorrect syntax near 'JSON_OBJECT'.

This issue is created as a part of follow-up for #137 since it was closed without a fix.

naveennaik1 avatar Nov 07 '25 06:11 naveennaik1