0%
Loading ...

MsSql – For Json auto

For Json variations

IndexSyntaxDescriptionExample (Simplified)Results (Simplified)
1FOR JSON PATHFormats the result as JSON with nestingSELECT name, surname FROM users FOR JSON PATH[{ “name”: “John”, “surname”: “Doe” }]
2FOR JSON PATH, ROOT(‘name’)Adds a root element to JSON outputSELECT name FROM users FOR JSON PATH, ROOT(‘users’){ “users”: [{ “name”: “John” }] }
3FOR JSON AUTOAutomatically formats result as JSONSELECT users.name, orders.order_id FROM users INNER JOIN orders ON users.user_id = orders.user_id FOR JSON AUTO[{ “name”: “John”, “orders”: [{ “order_id”: 123 }] }]
4FOR JSON AUTO, WITHOUT_ARRAY_WRAPPERFormats JSON without an array wrapperSELECT name FROM users FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER{ “name”: “John” }