I have a JSON array similar to this.
{
"first":
{
"heading":{
"row":[
{
"@captain" :"dhoni",
"@runs":"50"
},
{
"@captain" :"Kohli",
"@runs":"150"
}
]
}
}
}
But I am not sure how to add a sql script to import this JSON to my sql table. Can anyone help on this
You can insert the rows extracted from the json returned by your API call with the help of for each activity
and script
activity.
@pipeline().parameters.my_json['first']['heading']['row']
insert into dbo.player(captain,runs) values ('@{item()['@captain']}','@{item()['@runs']}')
Another approach using stored procedure:
create or alter procedure insert_player @json varchar(max)
as
begin
insert into player SELECT * FROM OPENJSON(@json,'$.first.heading.row') with ([@captain] varchar(30),[@runs] varchar(30))
end
@string(pipeline().parameters.my_json)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.