Hi,
I'm trying to return JSON from SQL and I'm getting this error. Can anyone explain why this is happening?
Database returned the following error: Error in advanced query SQL1: Incorrect syntax near the keyword 'SELECT'. Incorrect syntax near 'JSON_OBJECT'.
Hi @Mohan Raja ,
The error indicates that there is a syntax error in your SQL. To be able to determine what's the actual error we need to see the SQL you are trying to run. Please copy it here.
Hello,
Just to clarify your question: do you mean that you are trying to write a JSON format inside an Advanced Query, or have you already written the query and now want the output in JSON format?
@Mohan Raja : Do you mind sharing your SQL query and maybe the data model?
Hi @Mohan Raja
SQL Server doesn’t support JSON_OBJECT, so the error occurs. In OutSystems (SQL Server), you must build JSON using:
SELECT ... FOR JSON PATH
or:
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
* This is the correct and only supported way to return JSON in an Advanced Query.
Hope this helps,
Peter Hieu