Skip to content

Instantly share code, notes, and snippets.

@sbealer
Last active September 22, 2017 22:29
Show Gist options
  • Save sbealer/c2d4585570d9334861115c50208fb637 to your computer and use it in GitHub Desktop.
Save sbealer/c2d4585570d9334861115c50208fb637 to your computer and use it in GitHub Desktop.
Use JSON in Sql Server 2016
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