How to write this JSON-preparing, non-scalar query as scalar? I use something like the following to prepare a block of json:

SET @json = (SELECT 
  @varchar1 as MyVarchar1,
  @varchar2 as MyVarchar2, 
  GetUtcDate() as MyTime FOR JSON PATH);


Visual Studio complains that it's a "Non scalar subquery in place of scalar" - is there a way to write it so it doesn't elicit a warning?
In your scenario, because you are using variables, it is sure that your query returns only one row (scalar), so you can ignore this warning.

To suppress the warning, you could add a TOP 1 to your query, but it is not necessary.

SET @json = (SELECT TOP 1
  @varchar1 as MyVarchar1,
  @varchar2 as MyVarchar2, 
  GetUtcDate() as MyTime FOR JSON PATH);


You can find more on https://documentation.red-gate.com/codeanalysis/execution-rules/ei003