JOLT规范,用于支持输入json

时间:2019-05-21 10:54:05

标签: jolt

我的输入JSON如下所示,但是我不确定如何使用JOLT进行与内部数组相关的参数转换。感谢您的帮助,因为我是JOLT的新手

{
  "pktId": 7603,
  "seq": 1,
  "vehicleNumber": "66079",
  "rmdLocation": "1",
  "rmdTime": "2019-01-07T11:27:05.745Z",
  "position": {
    "lat": 55.4911232,
    "lng": -3.686831
  },
  "dataSource": 11,
  "frames": [
    {
      "seq": 0,
      "card": 8,
      "channel": 6,
      "value": 117
    },
    {
      "seq": 1,
      "card": 8,
      "channel": 6,
      "value": 120
    }
  ]
}

下面是我创建的规格文件,但它不完整

[
  {
    "operation": "shift",
    "spec": {
      "frames": {
        "*": {
          "seq": "parameters[&1].seq",
          "card": "parameters[&1].card",
          "channel": "parameters[&1].channel",
          "value": "parameters[&1].value"
        }
      },
      "rmdTime": "messageTime",
      "vehicleNumber": "roadNumber"
    }
  },
  {
    "operation": "default",
    "spec": {
      "appId": "configMsgXX",
      "customerId": "ABC",
      "messageRev": 1,
      "messageType": "customStatistics"
    }
  }
]

预期输出如下

{
  "appId": "configMsgXX",
  "customerId": "ABC",
  "deviceId": string1+roadNumber+string2",
  "messageRev": 1,
  "messageTime": 1543395341000,
  "messageType": "customStatistics",
  "parameters": [
    {
      "address": string1+string2,
      "name": "EM2000VoltageMainGenerator",
      "timestamp": 1543395341000,
      "quality": "3",
      "datatype": "INTEGER",
      "value": 100,
      "qualityReason": "Stale Data",
      "category": "REAL"
    }
  ],
  "roadNumber": 66079
}

我正在使用此库https://github.com/bazaarvoice/jolt

1 个答案:

答案 0 :(得分:0)

[
  {
    "operation": "shift",
    "spec": {
      "frames": {
        "*": {
          "seq": "parameters[&1].seq",
          "card": "parameters[&1].card",
          "channel": "parameters[&1].channel",
          "value": "parameters[&1].value",
          "@(2,rmdTime)": "parameters[&1].timestamp"
        }
      },
      "rmdTime": "messageTime",
      "vehicleNumber": "roadNumber"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "parameters": {
        "*": {
          "quality": "3",
          "name": "",
          "address": "",
          "datatype": "INTEGER",
          "qualityReason": "Stale Data",
          "category": "REAL"
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "appId": "configMsgXX",
      "customerId": "ABC",
      "messageRev": 1,
      "messageType": "customStatistics"
    }
  }
]