Nifi 的 JOLT 转换,展平数组和移动键
JOLT transformation for Nifi, flattening array and moving keys
我正在尝试展平 JSON 输出,同时将它的一部分移动到较低的数组中。在下面的示例中,我需要将所有内容都保留在“值”下,并将“时间戳”移到值结果中。有什么有用的提示或文档吗?
谢谢!
输入:
{ "readings": [
{
"meter": "78522546",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848206,
"ExportWh": 2136.5,
}
},
{
"timestamp": "22/02/2019 17:15:00",
"values": {
"DateTime": 1550848206,
"ExportWh": 2136.5,
}
}
]
},
{
"meter": "78522548",
"records": [
{
"timestamp": "22/02/2019 17:15:00",
"values": {
"DateTime": 1550848246,
"ExportWh": 0,
}
}
]
},
{
"meter": "78522570",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848226,
"ExportWh": 3152012603293.037,
}
}
]
},
{
"meter": "78522572",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848236,
"ExportWh": 1112.172,
}
}
]
},
{
"meter": "78522589",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848217,
"ExportWh": 0,
}
}
]
} ] }
期望的输出:
{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848206,
"ExportWh": 2136.5
},{
"timestamp": "22/02/2019 17:15:00",
"DateTime": 1550848206,
"ExportWh": 2136.5
},{
"timestamp": "22/02/2019 17:15:00",
"DateTime": 1550848246,
"ExportWh": 0
},{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848226,
"ExportWh": 3152012603293.037
},{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848236,
"ExportWh": 1112.172
},{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848217,
"ExportWh": 0
}
这是我对规范的了解程度,但从这里开始一直在兜圈子:
[
{
"operation": "shift",
"spec": {
"readings": {
"*": {
"records": {
"*": {
"timestamp": "&",
"@(0,values)": ""
}
}
}
}
}
}
]
检查此规范
[
{
"operation": "shift",
"spec": {
"readings": {
"*": {
"records": {
"*": {
"values": {
"@": "[].@(2,timestamp)"
}
}
}
}
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"*": {
"@": "[]",
"$": "[&2].timestamp"
}
}
}
}
]
我正在尝试展平 JSON 输出,同时将它的一部分移动到较低的数组中。在下面的示例中,我需要将所有内容都保留在“值”下,并将“时间戳”移到值结果中。有什么有用的提示或文档吗?
谢谢!
输入:
{ "readings": [
{
"meter": "78522546",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848206,
"ExportWh": 2136.5,
}
},
{
"timestamp": "22/02/2019 17:15:00",
"values": {
"DateTime": 1550848206,
"ExportWh": 2136.5,
}
}
]
},
{
"meter": "78522548",
"records": [
{
"timestamp": "22/02/2019 17:15:00",
"values": {
"DateTime": 1550848246,
"ExportWh": 0,
}
}
]
},
{
"meter": "78522570",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848226,
"ExportWh": 3152012603293.037,
}
}
]
},
{
"meter": "78522572",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848236,
"ExportWh": 1112.172,
}
}
]
},
{
"meter": "78522589",
"records": [
{
"timestamp": "22/02/2019 17:10:00",
"values": {
"DateTime": 1550848217,
"ExportWh": 0,
}
}
]
} ] }
期望的输出:
{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848206,
"ExportWh": 2136.5
},{
"timestamp": "22/02/2019 17:15:00",
"DateTime": 1550848206,
"ExportWh": 2136.5
},{
"timestamp": "22/02/2019 17:15:00",
"DateTime": 1550848246,
"ExportWh": 0
},{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848226,
"ExportWh": 3152012603293.037
},{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848236,
"ExportWh": 1112.172
},{
"timestamp": "22/02/2019 17:10:00",
"DateTime": 1550848217,
"ExportWh": 0
}
这是我对规范的了解程度,但从这里开始一直在兜圈子:
[
{
"operation": "shift",
"spec": {
"readings": {
"*": {
"records": {
"*": {
"timestamp": "&",
"@(0,values)": ""
}
}
}
}
}
}
]
检查此规范
[
{
"operation": "shift",
"spec": {
"readings": {
"*": {
"records": {
"*": {
"values": {
"@": "[].@(2,timestamp)"
}
}
}
}
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"*": {
"@": "[]",
"$": "[&2].timestamp"
}
}
}
}
]