Last active
September 22, 2017 22:29
-
-
Save sbealer/c2d4585570d9334861115c50208fb637 to your computer and use it in GitHub Desktop.
Use JSON in Sql Server 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @json varchar(2000) = '{ | |
"colors": [ | |
{ | |
"color": "black", | |
"category": "hue", | |
"type": "primary", | |
"code": { | |
"rgba": [255,255,255,1], | |
"hex": "#000" | |
} | |
}, | |
{ | |
"color": "white", | |
"category": "value", | |
"code": { | |
"rgba": [0,0,0,1], | |
"hex": "#FFF" | |
} | |
}, | |
{ | |
"color": "red", | |
"category": "hue", | |
"type": "primary", | |
"code": { | |
"rgba": [255,0,0,1], | |
"hex": "#FF0" | |
} | |
}]}'; | |
SELECT * | |
FROM OPENJSON(@json,'$.colors') | |
WITH ( | |
color varchar(200) '$.color', | |
hex varchar(100) '$.code.hex' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment