[英]Azure Data Factory - SQL to nested JSON
I have a SQL database with tables for Staff and Appointments (1 staff : many appointments).我有一个 SQL 数据库,其中包含员工和约会表(1 名员工:许多约会)。 I'd like to use Azure Data Factory to output this to nested JSON in a Blob store in a format similar to the below:
我想使用 Azure 数据工厂以类似于以下的格式将其输出到 Blob 存储中的嵌套 JSON:
[
{
"staffid":"101",
"firstname":"Donald",
"lastname":"Duck",
"appointments":[
{
"appointmentid":"201",
"startdate":"2020-02-01T00:00:00",
"enddate":"2020-04-29T23:00:00"
},
{
"appointmentid":"202",
"startdate":"2020-01-01T00:00:00",
"enddate":"2020-01-31T00:00:00"
}
]
},
{
"staffid":"102",
"firstname":"Mickey",
"lastname":"Mouse",
"appointments":[
{
"appointmentid":"203",
"startdate":"2020-02-01T00:00:00",
"enddate":"2020-04-29T23:00:00"
},
{
"appointmentid":"204",
"startdate":"2020-01-01T00:00:00",
"enddate":"2020-01-31T00:00:00"
}
]
}
]
I've tried using the Copy activity but this produces flat JSON structures rather than the nested structure described above.我曾尝试使用 Copy 活动,但这会生成平面 JSON 结构,而不是上述嵌套结构。 Has anyone got a way to do this please?
有没有人有办法做到这一点?
More scenarios for JSON data in ADF is flattening. ADF 中 JSON 数据的更多场景正在扁平化。 However,according to your description,your need producing JSON contains Json array group by some columns.Something like merge
appointment things
by same staff
.但是,根据您的描述,您需要按某些列生成包含 Json 数组组的 JSON。类似于合并同一
staff
appointment things
。
If my understanding is right,then you could get some clues from my previous case: How to split into Sub Documents with Nesting separator?如果我的理解是对的,那么你可以从我之前的案例中得到一些线索: 如何使用嵌套分隔符拆分为子文档? .
. Please refer to my test:
请参考我的测试:
Simulate your sample data:模拟您的样本数据:
Use sql in sql db source dataset:在 sql db 源数据集中使用 sql:
select app.staffid,app.firstname,app.lastname,
'appointments' = (
SELECT
appointmentid AS 'appointmentid',startdate as 'startdate',enddate as 'enddate'
FROM
dbo.appoint as app2
where app2.staffid = app.staffid and
app2.firstname = app.firstname and
app2.lastname = app.lastname
FOR JSON PATH)
from dbo.appoint as app
group by app.staffid,app.firstname,app.lastname
FOR JSON Path;
Output in blob storage: blob 存储中的输出:
I try to verify the json format and it is correct.我尝试验证json格式,它是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.