I have a table in a SQL Server database that stores JSON in one of its columns. The structure is as follows:
Table Person
| Name | ExtraInfo |
|--------|:------------------------------------------:|
| Bob | {"Age":"23","Colors":["Red","Blue"]} |
| James | {"Age":"26","Colors":["Green","Yellow"]} |
If I run this query:
select
Json_value(ExtraInfo,'$.Age') as Age,
json_query(ExtraInfo, '$.Colors') as Colors
from Persons
I will get something like this:
| Age |Colors |
|-----|:-------------------|
| 23 | ["Red","Blue"] |
| 26 | ["Green","Yellow"]|
However I would need transform the Colors
property of the JSON array into a nvarchar
column with all the values of the array concatenated by a space character like this:
| Age | Colors |
|-----|:-------------|
| 23 | Red Blue |
| 26 | Green Yellow |
Is there any way that I can compose multiple calls to json_query
or some other similar approach to accomplish this in a single SQL query?