簡體   English   中英

使用 jolt 轉換多個 json 對象

[英]Transforming multiple json objects using jolt

我正在嘗試使用 jolt 轉換此 json 輸入。 請幫助我的規格有什么問題。

JSON 輸入

{
  "ResultSets": {
    "ClassPaths": {
      "currentRow": 0,
      "fields": [
        {
          "name": "path"
        },
        {
          "name": "loadOrder"
        }
      ],
      "rows": [
        [
          "/a/b/genenerator.jar",
          "-10"
        ],
        [
          "/a/b/server.jar",
          "0"
        ]
      ]
    },
    "DisabledComponents": {
      "currentRow": 0,
      "fields": [
        {
          "name": "name"
        },
        {
          "name": "location"
        }
      ],
      "rows": [
        [
          "ActiveDirectoryLdapComponent",
          "/a/b/component.hda"
        ],
        [
          "AppAdapterCore",
          "/a/b/AdapterCore.hda"
        ]
      ]
    }
  }
}

預期 JSON Output

{
  "ResultSets" : {
    "ClassPaths" : [ {
      "path" : "/a/b/genenerator.jar",
      "loadOrder" : "-10"
    }, {
      "path" : "/a/b/server.jar",
      "loadOrder" : "0"
    } ],
     "DisabledComponents" : [ {
      "name" : "ActiveDirectoryLdapComponent",
      "location" : "/a/b/component.hda"
    }, {
      "name" : "AppAdapterCore",
      "location" : "/a/b/AdapterCore.hda"
    } ]
  }
}

我的規格是

[
  {
    "operation": "shift",
    "spec": {
      "ResultSets": {
        "*": {
          "rows": {
            "*": {
              "*": "ResultSets.&1.@(3,fields[&].name)"
            }
          }
        }
      }
    }
  }
]

如果我將 * 替換為密鑰名稱(ClassPath 或 DisabledComponents),它可以工作,但只提供 json 與該密鑰。

我無法對密鑰進行硬編碼,因為它是動態的,而且我們事先也不知道那里有什么。

所以我想要一個在規范中不指定確切鍵(ClassPath 或 DisabledComponents)的規范。

請幫忙。

謝謝,哈里

你幾乎是正確的。 這是產生預期 output 的規范:

[
  {
    "operation": "shift",
    "spec": {
      "ResultSets": {
        "*": {
          "rows": {
            "*": {
              "*": "ResultSets.&3[&1].@(3,fields[&].name)"
            }
          }
        }
      }
    }
  }
]

解釋:

  • &1 - 指數組內 object 的索引
  • 相反,我們希望將它放在相同的索引下,但由 object 包裹,該索引向上三層。 這就是為什么我們使用&3[&1]而不是&1 1

暫無
暫無

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

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