JOLT从前缀汤转换为嵌套



我正在接收这个JSON作为SQL查询的一部分,我想从组合属性中创建嵌套对象。如果是1个元素,这很容易做到,但是MYSQL查询在根返回一个数组:

[
{
"idlicense": 1,
"StartDate": "2022-11-15 00:00:00.0",
"EndDate": "2022-11-29 00:00:00.0",
"MonthlySearchMax": 500,
"Customer_CustomerId": 0,
"Customer_Guid": "c24c1fa3-0388-4c08-b431-8d0f05fe263a",
"Customer_Name": "User",
"Customer_CustStartDate": "2022-11-15 00:00:00.0",
"Connector_ConnectorId": 0,
"Connector_Name": "connector0",
"Connector_Version": "1.01"
},
{
"idlicense": 2,
"StartDate": "2022-11-15 00:00:00.0",
"EndDate": "2022-11-29 00:00:00.0",
"MonthlySearchMax": 500,
"Customer_CustomerId": 0,
"Customer_Guid": "c24c1fa3-0388-4c08-b431-8d0f05fe263a",
"Customer_Name": "User",
"Customer_CustStartDate": "2022-11-15 00:00:00.0",
"Connector_ConnectorId": 1,
"Connector_Name": "connector1",
"Connector_Version": "1.01"
}
]

我试图在NIFI上创建一个带有JOLT的嵌套JSON,但找不到合适的格式,看看可用的示例,似乎很简单。我需要最终的JSON看起来像这样:

{
"Licenses": [
{
"idLicense": "1",
"Customer": {
"CustomerId": "0",
"Guid": "c24c1fa3-0388-4c08-b431-8d0f05fe263a",
"Name": "User",
"CustStartDate": "2022-11-15 00:00:00.0"
},
"Connector": {
"ConnectorId": "0",
"Name": "Connector0",
"Version": "1.01"
}
},
{
"idLicense": "2",
"Customers": {
"CustomerId": "1",
"Guid": "c24c1fa3-0388-4c08-b431-8d0f05fe263a",
"Name": "User",
"CustStartDate": "2022-11-15 00:00:00.0"
},
"Connector": {
"ConnectorId": "1",
"Name": "Connector1",
"Version": "1.01"
}
}
]
}

到目前为止,我已经完成了这个JOLT转换:

{
"idlicense": [1,2],
"Customer": {
"CustomerId": [0,0],
"Guid": ["c24c1fa3-0388-4c08-b431-8d0f05fe263a","c24c1fa3-0388-4c08-b431-8d0f05fe263a"],
"Name": ["User","User"],
"CustStartDate": ["2022-11-15 00:00:00.0","2022-11-15 00:00:00.0"]
},
"Connector": {
"ConnectorId": [0,1],
"Name": ["Conector0","Connector1"],
"Version": ["1.01","1.01"]
}
}

感谢您的支持!

可以使用shift转换规范

[
{
"operation": "shift",
"spec": {
"*": {
"idlicense": "Licenses[&1].&",
"*_*": "Licenses[&1].&(0,1).&(0,2)"
}
}
}
]

,, (0, 1)&(0,2)下划线

之后

最新更新