我试图写一个规范来使用jolt转换完成下面的转换。我需要将平面JSON转换成嵌套JSON。
输入数据与此问题几乎相同。
Link:将平面json转换为具有多个数组的嵌套Json,并使用Jolt transform在输出中保留空值
我在将平面 JSON 转换为嵌套 JSON 时遇到了一些问题。在这里,我想基于 stoptype 属性聚合数据。我使用 https://jolt-demo.appspot.com 在下面测试以下内容。
输入Json:
[
{
"container_id": "ABC",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"priority": null,
"loadNumber": "123345",
"billOfLading": "12345",
"addressLine1": "ABC Street",
"addressLine2": null,
"city": "Chicago",
"country": "US",
"latitude": null,
"longitude": null,
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"postalCode": "XXXXX3",
"sequence": "1",
"state": "XY",
"stopReferenceId": "0001",
"stopType": "PU",
"containerNumber": "XXXXXXXX"
},
{
"container_id": "ABC",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"priority": null,
"loadNumber": "123345",
"billOfLading": "12345",
"addressLine1": null,
"addressLine2": null,
"city": null,
"country": null,
"latitude": null,
"longitude": null,
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"name": null,
"postalCode": null,
"sequence": "2",
"state": null,
"stopReferenceId": "XXXXD",
"stopType": "PL",
"containerNumber": "XXXXXXXX"
}
]
预期输出:
[
{
"container_id": "ABC",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"priority": null,
"loadNumber": "123345",
"billOfLading": "12345",
"PU":
{
"addressLine1": "ABC Street",
"city": "Chicago",
"country": "US",
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"postalCode": "XXXXX3",
"sequence": "1",
"state": "XY",
"stopReferenceId": "0001",
"stopType": "PU"
},
"PL" : {
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"sequence": "2",
"stopReferenceId": "dummy",
"stopType": "PL",
"externalAddressId": "dummy"
},
"containerNumber": "XXXXXXXX"
}
]
这里是我在最后一个问题中使用的相同的颠簸规格。链接:使用多个数组将Flat json转换为Nested json,并使用Jolt转换在输出中保留空值
您可以使用以下说明的规格
json prettyprint-override">[
{
"operation": "shift",
"spec": {
"*": {
"*": "&",
"addressLine1": "@(1,stopType).&",
"addressLine2": "@(1,stopType).&",
"city": "@(1,stopType).&",
"country": "@(1,stopType).&",
"*AppointmentTime": "@(1,stopType).&",
"sequence": "@(1,stopType).&",
"state": "@(1,stopType).&",
"stop*": "@(1,stopType).&",
"post*": "@(1,stopType).&",
"lat*|lon*|name": { // in order individually to get rid of the undesired null valued attributes
"$": "@(0)"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"PU|PL": {
"*": {
"$": "&2.&1.@(0)" // in order to get rid of all undesired null valued attributes nested within the subobjects PU and PL
}
}
}
},
{
// revert key-value pairs in order to obtain the originals
"operation": "shift",
"spec": {
"container_id|shipperN|PNumber|trackingNumber|priority|loadNumber|billOfLading": "&", // indeed using "*":"&" is enough, but replaced after wish of sorting the containerNumber attribute at the bottom of the object
"PU|PL": {
"*": {
"*": {
"$": "&3.@(0)"
}
}
},
"containerNumber": "&"
}
},
{
// reduce only to a single one for the repeating components of the arrays
"operation": "cardinality",
"spec": {
"*": "ONE"
}
},
{
"operation": "shift",
"spec": {
"@": "[]"
}
}
]
网站上 https://jolt-demo.appspot.com/ 演示是
所以目前我看到的是这样的: 这是我目前编写的Jolt规范(编辑): 以及转换后的输出: 任何帮助都是非常感谢的。
输入 json : 预期输出: 我想有一个颠簸转换,它可以嵌套很少的田地。
我有一个关于使用jolt将平面json转换成嵌套json的问题。我对jolt很陌生,这是我的意见 我编写了jolt spec,但我没有得到想要的输出 我的预期产出是: 任何震动专家都可以帮助我获得所需的输出。我应该在颠簸中使用多个变换,还是可以在一个震动变压器中获得所需的输出?
我试图写一个规范来使用jolt转换完成下面的转换。我需要将平面JSON转换成嵌套JSON。 输入数据: 我在将平面JSON转换为嵌套JSON时遇到了一些问题。这里,我希望基于stoptype属性聚合数据,并且需要针对唯一的有效负载进行聚合。我用https://jolt-demo.appspot.com来测试以下内容。 输出: 你能帮我完成这个预期的输出吗?
输入 JSON : 预期输出JSON: 目前,我正在使用JOLTtransformJSON处理器和JOLT规范: 但我得到的输出要么是NULL,要么是原始JSON(带有差异规范)。提前感谢。
如何使用jolt转换将平面JSON转换为嵌套JSON?我对JSON和jolt是新手。 输入: 预期输出: 编辑:我想在< code>SubFunds中添加一个新字段,但是新字段不在JSON文件中,它是计算字段,我可以按原样添加示例吗 并重命名字段: