SqlScriptDOM icon indicating copy to clipboard operation
SqlScriptDOM copied to clipboard

Add support for `JSON_OBJECTAGG` keyword in TSql170Parser

Open naveennaik1 opened this issue 3 months ago • 2 comments

We have encountered a parsing issue in Microsoft Documentation in JSON_OBJECTAGG using TSql170Parser 170.128.0.

Example script

SELECT JSON_OBJECTAGG( t.c1 : t.c2 )
FROM (
    VALUES('key1', 'c'), ('key2', 'b'), ('key3','a')
) AS t(c1, c2);

Steps to reproduce

        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 ':'

naveennaik1 avatar Oct 22 '25 09:10 naveennaik1

@naveennaik1 which version of ScriptDom are you using?

llali avatar Nov 12 '25 17:11 llali

@llali I have tried it with v170.128.0 and it gives the same error.

One thing to keep in mind here would be that it only seems to fail when we use an alias before the colon :

Scenario 1

SELECT JSON_OBJECTAGG( t.c1 : t.c2 )
FROM (
    VALUES('key1', 'c'), ('key2', 'b'), ('key3','a')
) AS t(c1, c2);

Error Message : Incorrect syntax near ':'

Scenario 2

SELECT JSON_OBJECTAGG( c1 : t.c2 )
FROM (
    VALUES('key1', 'c'), ('key2', 'b'), ('key3','a')
) AS t(c1, c2);

Does not throw any error.

naveennaik1 avatar Nov 12 '25 17:11 naveennaik1

fixed in 170.147.0

llali avatar Dec 15 '25 16:12 llali