I want to write a stored procedure that returns nested json. I'm currently trying to write the query to do this and I'm a little confused about the format I need to write it in.
I want json that looks something like this:
{
[{
item: "string",
item2: 0,
groups: [{
item: "string",
item2: "string",
sub_groups[{
item: "string",
item2: "string"
}, {
item: "string",
item2: "string"
}]
}, {
item: "string",
item2: "string",
sub_groups[{
item: "string",
item2: "string"
}, {
item: "string",
item2: "string"
}]
}]
}, {
item: "string",
item2: 0,
groups: [{
item: "string",
item2: "string",
sub_groups[{
item: "string",
item2: "string"
}, {
item: "string",
item2: "string"
}]
}, {
item: "string",
item2: "string",
sub_groups[{
item: "string",
item2: "string"
}, {
item: "string",
item2: "string"
}]
}]
}]
}
An array of objects that contain values, and an array of objects that contain values, and an array of objects that contain values.
Or to put it differently, I have a table that has a one to many relationship with another table that has a one to many relationship to a third table and I want to print out json that represents this.
I have tried to write a query for this but I'm new to SQL and I'm having difficulty withing a "nested query." I'm not sure that you could even do that with normal SQL because you would just need to print all this information from the outer nests over again the same number of times you have results for the inner nests.