您好,我有以下 json,想取消嵌套归档。所以,我有一个旧订单和新订单的产品。 json 可能有更多字段,但嵌套级别保持不变。是否可以通过 Jolt 来做到这一点? 我可以在输出中包含 new_something 和 old_something 等字段
{
"data": {
"new": {
"orders": {
"type": "atype",
"currency": "usd",
"name": null,
"code": null,
"shipped": null,
"identifier": "some uuid",
"source": "webshop",
"productinfo": [
{
"pType": "fan",
"ts": "2024-11-15T13:33:16.047Z",
"status": null,
"seller": {
"identifier": "uuid",
"internacodes": [
{
"type": "US",
"value": "1111"
},
{
"type": "UUID",
"value": "some uuid"
}
]
}
},
{
"pType": "fan",
"ts": "2024-11-25T13:33:16.047Z",
"status": null,
"seller": {
"identifier": "uuid",
"internacodes": [
{
"type": "US",
"value": "1111"
},
{
"type": "UUID",
"value": "some uuid"
}
]
}
}
],
"unique_num": [
{
"type": "UUID",
"value": "some uuid",
"ts": "2024-11-13T25:15:47.919Z"
},
{
"type": "product id",
"value": "23456",
"ts": "2024-11-22T15:15:46.912Z"
}
]
}
},
"old": {
"orders": {
"type": "atype",
"currency": "usd",
"name": null,
"code": null,
"shippedOffice": null,
"identifier": "some uuid",
"source": "webshop",
"productinfo": [
{
"pType": "fan",
"ts": "2024-11-15T13:33:16.047Z",
"status": null,
"seller": {
"identifier": "uuid",
"internacodes": [
{
"type": "US",
"value": "1111"
},
{
"type": "UUID",
"value": "some uuid"
}
]
}
}
],
"unique_num": [
{
"type": "UUID",
"value": "some uuid",
"ts": "2024-11-13T25:15:47.919Z"
},
{
"type": "product id",
"value": "23456",
"ts": "2024-11-22T15:15:46.912Z"
}
]
}
}
}
}
请分享建议和意见。我尝试通过 Jolt 中的硬编码操作,但可能会添加非嵌套字段。嵌套字段保持不变。 我需要这样的输出 -
{
"data.new.orders.type": "atype",
"data.new.orders.currency": "usd"
.....
"data.new.orders.productinfo.seller.identifier": "seller_identifier"
}
嗨,这个规范可以帮助您实现它。
给你一小块有2个字段的:
基本上我会跳过“。”运算符“\”转义字符“\”。
[
{
"operation": "shift",
"spec": {
"data": {
"new": {
"orders": {
"type": "&3\\.&2\\.&1\\.&",
"currency": "&3\\.&2\\.&1\\.&"
}
}
}
}
}
]