I'm not sure how you get SQL Server to produce JSON, but you could produce something similar in XML. Perhaps there is a way to convert XML to JSON..
I'm assuming your schema is something like this:
CREATE TABLE [Thing]
(
[id] INT,
[x] INT,
[y] INT,
[type] VARCHAR(10)
)
CREATE TABLE [Map_Settings]
(
[Thing_id] INT,
[MapSetting1] INT,
[MapSetting2] INT
)
CREATE TABLE [Graph_Settings]
(
[Thing_id] INT,
[GraphSetting3] INT,
[GraphSetting4] INT
)
Some data:
INSERT [Thing] VALUES (1, 1, 1, 'map'), (2, 1, 1, 'graph')
INSERT [Map_Settings] VALUES (1, 0, 0)
INSERT [Graph_Settings] VALUES (2, 0, 0)
And a query that produces XML:
SELECT
thing.id AS [@id],
thing.[x] AS [@x],
thing.[y] AS [@y],
thing.[type] AS [@type],
CASE thing.[type]
WHEN 'map' THEN
(
SELECT [MapSetting1] AS [@mapsetting1], [MapSetting2] AS [@mapsetting2]
FROM [Map_Settings] ms
WHERE ms.[Thing_id] = thing.[id]
FOR XML PATH ('settings'), TYPE
)
WHEN 'graph' THEN
(
SELECT [GraphSetting3] AS [@graphsetting3], [GraphSetting4] AS [@graphsetting4]
FROM [Graph_Settings] gs
WHERE gs.[Thing_id] = thing.[id]
FOR XML PATH ('settings'), TYPE
)
END
FROM [Thing] thing
FOR XML PATH ('Thing')
The output:
<Thing id="1" x="1" y="1" type="map">
<settings mapsetting1="0" mapsetting2="0" />
</Thing>
<Thing id="2" x="1" y="1" type="graph">
<settings graphsetting3="0" graphsetting4="0" />
</Thing>
Does this help?