JOLT 从 LHS 移动到 RHS 并变平

JOLT moving from LHS to RHS and flattening

我正在尝试使用 JOLT 转换以下 JSON,但遇到困难,如有任何帮助,我们将不胜感激。

{
  "2021-04-14T00:00:00+02:00": {
    "249184": {
      "SRAD": null,
      "T": -50.00000000000001
    },
    "249185": {
      "SRAD": 0.46133333444595337,
      "T": null
    }
  },
  "2021-04-14T00:15:00+02:00": {
    "249184": {
      "SRAD": null,
      "T": -50.00000000000001
    },
    "249185": {
      "SRAD": 0.4593333303928375,
      "T": null
    }
  }
}

所需输出:请注意,每个设备 ID 的时间戳与 SRAD 和 T 值一起重复。

{
    "timestamp": "2021-04-14T00:00:00+02:00",
    "deviceID": 249184,
    "SRAD":null,
    "T":-50.00000000000001
},
{
    "timestamp": "2021-04-14T00:00:00+02:00",
    "deviceID": 249185,
    "SRAD":0.46133333444595337,
    "T":null
},
{
    "timestamp": "2021-04-14T00:15:00+02:00",
    "deviceID": 249184,
    "SRAD":null,
    "T":-50.00000000000001
},
{
    "timestamp": "2021-04-14T00:15:00+02:00",
    "deviceID": 249185,
    "SRAD": 0.4593333303928375,
    "T":null
}

我尝试了很多东西,但一直在兜圈子。

[
  // Change null as String, as jolt will not 
  // process null values
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "*": {
          "SRAD": "null",
          "T": "null"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "SRAD": "&4.SRAD",
          "T": "&4.T",
          "[=10=]": "&4.deviceID",
          "": "&4.timestamp"
        }
      }
    }
  }, {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "@": "&"
          }
        }
      }
    }
  }, {
    "operation": "shift",
    "spec": {
      "*": {
        "0": "[&1].deviceID",
        "1": "[&1].timestamp",
        "2": "[&1].SRAD",
        "3": "[&1].T"
      }
    }
  }
]

您无法处理具有 null 作为值的 JSON,因此使用 modify-default-beta 操作将 null 替换为“null”。

输入 JSON 按时间戳和设备 ID 分组,因此通过为子节点分配名称来解构 json,然后构造输出 JSON.

这是一个具有 2 个班次的替代规范,支持 deviceId 对象内的任意数量的字段:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$(1)": "a[].timestamp",
          "$": "b[].deviceId",
          "@": "c[]"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "a": {
        "*": {
          "timestamp": "[&1].timestamp",
          "@(2,b[&])": "[&1]"
        }
      },
      "b": null,
      "c": {
        "*": {
          "*": "[&1].&"
        }
      }
    }
  }
]