0%
Loading ...

MsSql – For Json auto

For Json variations

Index Syntax Description Example (Simplified) Results (Simplified)
1 FOR JSON PATH Formats the result as JSON with nesting SELECT name, surname FROM users FOR JSON PATH [{ “name”: “John”, “surname”: “Doe” }]
2 FOR JSON PATH, ROOT(‘name’) Adds a root element to JSON output SELECT name FROM users FOR JSON PATH, ROOT(‘users’) { “users”: [{ “name”: “John” }] }
3 FOR JSON AUTO Automatically formats result as JSON SELECT 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 }] }]
4 FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER Formats JSON without an array wrapper SELECT name FROM users FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER { “name”: “John” }