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

json - Need jolt spec where output is populated from different section of input - Stack Overflow

programmeradmin1浏览0评论

We need a jolt spec which will give below output for the mentioned input. The jolt which I tried is working for all the section except "ratePeriods" block which is not appearing at all."allotmentPeriods","inventoryTypeCode" & "isFlowThrough" section in output json is populating from "offer" section in input json(which is working as expected), but "ratePeriods" should populated from "pricePlans" section of input json.under "ratePeriods" , "startDate" and "endDate" will come from "period" of input section and "inventoryTypeRate" should populate from the "value" where "occupancy": 1

input json

{
  "message": {
    "data": {
      "offer": {
        "productUses": [
          {
            "inventoryTypeCode": "ABCD",
            "period": {
              "start": "2025-03-08",
              "end": "2025-03-10"
            },
            "id": 1,
            "guestCounts": [
              {
                "count": 1,
                "otaCode": "AQC10"
              }
            ],
            "countersPerInventoryType": {
              "allocated": 35,
              "deducted": 15,
              "isFlowThrough": true,
              "originalAllocated": [
                {
                  "period": {
                    "start": "2025-03-08",
                    "end": "2025-03-10"
                  },
                  "value": "35"
                }
              ]
            }
          },
          {
            "inventoryTypeCode": "WXYZ",
            "period": {
              "start": "2025-03-08",
              "end": "2025-03-10"
            },
            "id": 2,
            "guestCounts": [
              {
                "count": 1,
                "otaCode": "AQC10"
              }
            ],
            "countersPerInventoryType": {
              "allocated": 35,
              "deducted": 15,
              "isFlowThrough": true,
              "originalAllocated": [
                {
                  "period": {
                    "start": "2025-03-08",
                    "end": "2025-03-10"
                  },
                  "value": "35"
                }
              ]
            }
          }
        ]
      },
      "groupContract": {
        "pricePlans": [
          {
            "amountRules": [
              {
                "type": "AmountRule",
                "period": {
                  "start": "2025-03-08",
                  "end": "2025-03-08"
                },
                "inventoryTypes": {
                  "ABCD": [
                    {
                      "computationType": "Flat",
                      "value": "90.00",
                      "occupancy": 1
                    },
                    {
                      "computationType": "Flat",
                      "value": "100.00",
                      "occupancy": 2
                    }
                  ],
                  "WXYZ": [
                    {
                      "computationType": "Flat",
                      "value": "90.00",
                      "occupancy": 1
                    },
                    {
                      "computationType": "Flat",
                      "value": "100.00",
                      "occupancy": 2
                    }
                  ]
                }
              },
              {
                "type": "AmountRule",
                "period": {
                  "start": "2025-03-09",
                  "end": "2025-03-09"
                },
                "inventoryTypes": {
                  "ABCD": [
                    {
                      "computationType": "Flat",
                      "value": "90.00",
                      "occupancy": 1
                    },
                    {
                      "computationType": "Flat",
                      "value": "100.00",
                      "occupancy": 2
                    }
                  ],
                  "WZYZ": [
                    {
                      "computationType": "Flat",
                      "value": "135.00",
                      "occupancy": 1
                    }
                  ]
                }
              }
            ]
          }
        ]
      }
    }
  }
}

Expected Output json:

{
  "message" : {
    "groupBlock" : {
      "inventoryTypes" : [
      {
        "allotmentPeriods" : [ {
          "startDate" : "2025-03-08",
          "endDate" : "2025-03-10",
          "groupsDeducted" : [ 15 ],
          "groupsAllocated" : [ 35 ]
        } ],
        "ratePeriods": [
        {
          "startDate": "2025-03-08",
          "endDate": "2025-03-08",
          "inventoryTypeRate": "90.00"
        },
         {
          "startDate": "2025-03-09",
          "endDate": "2025-03-09",
          "inventoryTypeRate": "90.00"
        }
      ],
     
        "inventoryTypeCode" : "ABCD",
        "isFlowThrough" : true
      },

      {
        "allotmentPeriods" : [ {
          "startDate" : "2025-03-08",
          "endDate" : "2025-03-10",
          "groupsDeducted" : [ 15 ],
          "groupsAllocated" : [ 35 ]
        } ],
         "ratePeriods": [
        {
          "startDate": "2025-03-08",
          "endDate": "2025-03-08",
          "inventoryTypeRate": "90.00"
        },
        {
          "startDate": "2025-03-09",
          "endDate": "2025-03-09",
          "inventoryTypeRate": "135.00"
        }
      ],
        "inventoryTypeCode" : "WXYZ",
        "isFlowThrough" : true
      } 
      
      ]
    }
  }
}

current jolt:

[
  {
    "operation": "shift",
    "spec": {
      "message": {
        "*": {
          "offer": {
            "productUses": {
              "*": {
                "period": {
                  "start": "message.groupBlock.inventoryTypes[#3].allotmentPeriods[#].startDate",
                  "end": "message.groupBlock.inventoryTypes[#3].allotmentPeriods[#].endDate"
                },
                "inventoryTypeCode": "message.groupBlock.inventoryTypes[&1].inventoryTypeCode",
                "countersPerInventoryType": {
                  "isFlowThrough": "message.groupBlock.inventoryTypes[&2].isFlowThrough",
                  "deducted": "message.groupBlock.inventoryTypes[#3].allotmentPeriods[#].groupsDeducted[]",
                  "allocated": "message.groupBlock.inventoryTypes[#3].allotmentPeriods[#].groupsAllocated[]"
                }
              }
            }
          },
          "groupContract": {
            "pricePlans": {
              "*": {
                "amountRules": {
                  "*": {
                    "inventoryTypes": {
                      "*": {
                        "0": { //take from the first object of the array
                          "@3,period": {
                            "start": "message.groupBlock.&5_&3.inventoryTypes.ratePeriods[#3].startDate",
                            "end": "message.groupBlock.&5_&3.inventoryTypes.ratePeriods[#3].endDate"
                          },
                          "value": "message.groupBlock.&4_&2.inventoryTypes.ratePeriods[#2].inventoryTypeRate"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "message": {
        "groupBlock": {
          "inventoryTypes": "message.groupBlock.inventoryTypes"
        }
      }
    }
  }

  ]
发布评论

评论列表(0)

  1. 暂无评论