Mistake: treating FOR JSON modes as interchangeable. AUTO derives hierarchy from column order and JOIN order, while PATH lets aliases explicitly name nested properties. section 3.5
Generate an employee address document
SELECT 1 AS 'EmployeeID', '5331 Rexford Court' AS 'Address.Line1', 'Montgomery' AS 'Address.City', 'AL' AS 'Address.State', '36116' AS 'Address.ZipCode' FOR JSON PATH, ROOT ('EmployeeAddress'); section 3.5
Use the clause safely by remembering:
- Use PATH when property names and hierarchy require granular control. section 3.5
- Use AUTO cautiously: it requires a table, so an arbitrary FROM source and TOP 1 may be needed. section 3.5
