最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Assign Missing acceptId Using acceptIds List in JOLT Transformation - Stack Overflow

programmeradmin5浏览0评论

I have a JSON input where:

  1. acceptIds is an array containing some IDs.
  2. phoneNumbers is an array of objects.
  3. Some objects inside phoneNumbers contain an accept object but are missing the acceptId field.
  4. The number of IDs in acceptIds is always equal to the number of accept objects missing acceptId.

I need a JOLT transformation to assign values from acceptIds to acceptId only where it is missing, while keeping the rest of the structure unchanged.

Example Input:

{
  "acceptIds": [
    "23"
  ],
  "phoneNumbers": [
    {
      "phoneNumber": "123",
      "accept": {
        "acceptId": "1",
        "acceptName": "phone"
      }
    },
    {
      "phoneNumber": "456"
    },
    {
      "phoneNumber": "789",
      "accept": {
        "acceptName": "phone"
      }
    }
  ]
}

Expected Output:

{
  "phoneNumbers": [
    {
      "phoneNumber": "123",
      "accept": {
        "acceptId": "1",
        "acceptName": "phone"
      }
    },
    {
      "phoneNumber": "456"
    },
    {
      "phoneNumber": "789",
      "accept": {
        "acceptId": "23",
        "acceptName": "phone"
      }
    }
  ]
}

Requirements:

acceptIds should only be used for objects where accept.acceptId is missing. The order of acceptIds should be maintained while filling the missing values. If an object does not have an accept object, it should remain unchanged. How can I achieve this using JOLT transformation?

发布评论

评论列表(0)

  1. 暂无评论