簡體   English   中英

使用 jolt 從 json 中刪除和打印名稱/值對

[英]Removing and printing name/value pair from json using jolt

我想從 json 數組中刪除名稱/值對並將其打印到外面。 我首先嘗試這個,然后將整個請求擴展為 json 數組。 上面提到的解決方案似乎不起作用。

輸入:

[
  {
    "createdBy": "Admin",
    "createdDate": "2022-09-08",
    "modifiedBy": "Admin",
    "attrs": [
      {
        "name": "Type",
        "value": "Postpaid"
      },
      {
        "name": "subscriber",
        "value": "Paid"
      },
      {
        "name": "Details",
        "value": {
          "createdDate": "today",
          "description": "offer",
          "id": null
        }
      }
    ],
    "relatedInfo": [
      {
        "type": "Number",
        "name": "000000"
      },
      {
        "type": "Type",
        "name": "Post"
      }
    ]
  },
  {
    "createdBy": "Admin",
    "createdDate": "2022-09-08",
    "modifiedBy": "Admin",
    "attrs": [
      {
        "name": "Type",
        "value": "Postpaid"
      },
      {
        "name": "subscriber",
        "value": "Paid"
      },
      {
        "name": "Details",
        "value": {
          "createdDate": "today",
          "description": "offer",
          "id": null
        }
      }
    ],
    "relatedInfo": [
      {
        "type": "Number",
        "name": "000000"
      },
      {
        "type": "Type",
        "name": "Post"
      }
    ]
  }
]

所需的 Output:

[
  {
    "createdBy": "Admin",
    "createdDate": "2022-09-08",
    "modifiedBy": "Admin",
    "attrs": [
      {
        "name": "Type",
        "value": "Postpaid"
      },
      {
        "name": "subscriber",
        "value": "Paid"
      }
    ],
    "Details": {
      "createdDate": "today",
      "description": "offer",
      "id": null
    },
    "relatedInfo": [
      {
        "type": "Number",
        "name": "000000"
      },
      {
        "type": "Type",
        "name": "Post"
      }
    ]
  },
  {
    "createdBy": "Admin",
    "createdDate": "2022-09-08",
    "modifiedBy": "Admin",
    "attrs": [
      {
        "name": "Type",
        "value": "Postpaid"
      },
      {
        "name": "subscriber",
        "value": "Paid"
      }
    ],
    "Details": {
      "createdDate": "today",
      "description": "offer",
      "id": null
    },
    "relatedInfo": [
      {
        "type": "Number",
        "name": "000000"
      },
      {
        "type": "Type",
        "name": "Post"
      }
    ]
  }
]    

當前顛簸規格:

[
  {
    "operation": "shift",
    "spec": {
      "*": "[&]",
      "attrs": {
        "*": {
          "name": {
            "*": { "@2": "&4" },
            "Details": {
              "@(2,value)": "&1"
            }
          }
        }
      }
    }
  }
]

我似乎無法弄清楚在數組的情況下顛簸規范會如何變化

到目前為止一切順利,只需要在一個公共節點處組合屬性即可。 為此,我使用了標識符[&1][&5]以達到樹中最外層索引的級別,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].&",
        "attrs": {
          "*": {
            "name": {
              "*": { 
                "@2": "[&5].&4" 
              },
              "Details": {
                "@(2,value)": "[&5].&1"
              }
            }
          }
        }
      }
    }
  }
]

暫無
暫無

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

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