I have data stored in a database like so:
name VARCHAR(20),
host VARCHAR(200),
username varchar(50),
password varchar(50)
I can run the following as a query
select name,
host,
username as 'credentials.username',
password as 'credentials.password'
from tablename
FOR JSON PATH
which gives me a JSON like:
[
{
name:'MyItem',
host:'www.google.com',
credentials: {
username: 'usernamevalue',
password: 'passwordvalue'
}
}
]
What I would like to get:
[
MyItem: {
host:'www.google.com',
credentials: {
username: 'usernamevalue',
password: 'passwordvalue'
}
}
]
If I use a ROOT after the FOR JSON PATH, it will set that outside the array as the root name.
Essentially, I want each item in the array returned to be named for a value. In this case, the name field in the select statement.
Is this possible?