簡體   English   中英

如何使用Jolt Specification將Json轉換為Json?

[英]How to transform Json to Json using Jolt Specification?

我有這樣的JSON負載;

   [ {
      "Samples" : {
        "Load" : [ {
          "dataItemId" : "a5",
          "timestamp" : "2019-02-17T04:58:44.097Z",
          "name" : "Aload",
          "sequence" : "19",
          "subType" : null,
          "content" : null
        }, {
          "dataItemId" : "a7",
          "timestamp" : "2019-02-17T04:58:44.097Z",
          "name" : "AAA",
          "sequence" : "19",
          "subType" : null,
          "content" : null
        } ],
        "Angle" : [ {
          "dataItemId" : "a6",
          "timestamp" : "2019-02-17T04:58:44.097Z",
          "name" : "Aact",
          "sequence" : "20",
          "subType" : "ACTUAL",
          "content" : null
        } ]
      }
    } ]

我想接收這樣的JSON

{
      "Samples" : [
            {
              "tag_name": "Load",
              "dataItemId" : "a5",
              "timestamp" : "2019-02-17T04:58:44.097Z",
              "name" : "Aload",
              "sequence" : "19",
              "subType" : null,
              "content" : null
            }, {
              "tag_name": "Load",
              "dataItemId" : "a7",
              "timestamp" : "2019-02-17T04:58:44.097Z",
              "name" : "AAA",
              "sequence" : "19",
              "subType" : null,
              "content" : null
            }, {
              "tag_name": "Angle",
              "dataItemId" : "a6",
              "timestamp" : "2019-02-17T04:58:44.097Z",
              "name" : "Aact",
              "sequence" : "20",
              "subType" : "ACTUAL",
              "content" : null
            }
      ]
}

在我的場景中,我必須轉換上面定義的每個json數據。 每秒接收500個JSON數據 如何使用Jolt Specification執行此操作? 震動規格很快嗎? 適合流媒體嗎? 還是我應該為此編寫自己的腳本

如果您的有效載荷是具有單個對象的數組,則此規范適用:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Samples": {
          "*": {
            "*": {
              "$1": "Samples.&2[#2].tag_name",
              "*": "Samples.&2[#2].&"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Samples": {
        "*": {
          "*": "Samples[]"
        }
      }
    }
  }
]

否則,您可能需要拆分數組,對每個元素進行轉換,然后使用MergeContent或MergeRecord將它們重新組合在一起。 或者,您可以使用JoltTransformRecord將規范應用到數組中的每個元素/記錄,只需更改規范即可在第一次shift操作中刪除初始*部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM