json - Need a jolt spec to produce output where "start" and "end" will be copied within each

Need a jolt spec that will produce a"ratePeriods" block for each "inventoryTypeCode&qu

Need a jolt spec that will produce a "ratePeriods" block for each "inventoryTypeCode", and for each period( "start" and "end") date range combination.

Like here for range "start": "2025-03-08" to "end": "2025-03-08" and for ABCD type inventoryTypeCode, it will create a "ratePeriods" block containing startDate , endDate and inventoryTypeRate as first value of "value" under "inventoryTypes".

For ex, for ABCD we will have two ratePeriods for each date range one for 2025-03-08 and other one for 2025-03-09 date range.

input json:

{
  "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",
            "dow": "------S"
          },
          "inventoryTypes": {
            "ABCD": [
              {
                "computationType": "Flat",
                "value": "90.00",
                "occupancy": 1
              },
              {
                "computationType": "Flat",
                "value": "100.00",
                "occupancy": 2
              }
            ],
            "WZYZ": [
              {
                "computationType": "Flat",
                "value": "135.00",
                "occupancy": 1
              }
            ]
          }
        }
      ]
    }
  ]
}

output json:

{
  "inventoryTypes": [
    {
      "ratePeriods": [
        {
          "startDate": "2025-03-08",
          "endDate": "2025-03-08",
          "inventoryTypeRate": "90.00"
        }
      ],
      "inventoryTypeCode": "ABCD"
    },
   {
      "ratePeriods": [
        {
          "startDate": "2025-03-09",
          "endDate": "2025-03-09",
          "inventoryTypeRate": "90.00"
        }
      ],
      "inventoryTypeCode": "ABCD"
    },
    {
      "ratePeriods": [
        {
          "startDate": "2025-03-08",
          "endDate": "2025-03-08",
          "inventoryTypeRate": "90.00"
        }
      ],
      "inventoryTypeCode": "WXYZ"
    },
    {
      "ratePeriods": [
        {
          "startDate": "2025-03-09",
          "endDate": "2025-03-09",
          "inventoryTypeRate": "135.00"
        }
      ],
      "inventoryTypeCode": "WXYZ"
    }
  ]
}

jolt spec I tried

[
  {
    "operation": "shift",
    "spec": {
      "pricePlans": {
        "*": {
          "amountRules": {
            "*": {
              "period": {
                "start": "inventoryTypes[#3].ratePeriods[#2].startDate",
                "end": "inventoryTypes[#3].ratePeriods[#2].endDate"
              },
              "inventoryTypes": {
                "*": {
                  "0": {
                    "value": "inventoryTypes[#3].ratePeriods[#2].inventoryTypeRate"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

but this is giving me 2 block of ratePeriods but i need 4 in this case each containing both values "inventoryTypeRate" together it has to come in differently."inventoryTypeCode": "ABCD" im populating form a different part and working perefctly so that can be ignored here, this is a part of the json.

Need a jolt spec that will produce a "ratePeriods" block for each "inventoryTypeCode", and for each period( "start" and "end") date range combination.

Like here for range "start": "2025-03-08" to "end": "2025-03-08" and for ABCD type inventoryTypeCode, it will create a "ratePeriods" block containing startDate , endDate and inventoryTypeRate as first value of "value" under "inventoryTypes".

For ex, for ABCD we will have two ratePeriods for each date range one for 2025-03-08 and other one for 2025-03-09 date range.

input json:

{
  "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",
            "dow": "------S"
          },
          "inventoryTypes": {
            "ABCD": [
              {
                "computationType": "Flat",
                "value": "90.00",
                "occupancy": 1
              },
              {
                "computationType": "Flat",
                "value": "100.00",
                "occupancy": 2
              }
            ],
            "WZYZ": [
              {
                "computationType": "Flat",
                "value": "135.00",
                "occupancy": 1
              }
            ]
          }
        }
      ]
    }
  ]
}

output json:

{
  "inventoryTypes": [
    {
      "ratePeriods": [
        {
          "startDate": "2025-03-08",
          "endDate": "2025-03-08",
          "inventoryTypeRate": "90.00"
        }
      ],
      "inventoryTypeCode": "ABCD"
    },
   {
      "ratePeriods": [
        {
          "startDate": "2025-03-09",
          "endDate": "2025-03-09",
          "inventoryTypeRate": "90.00"
        }
      ],
      "inventoryTypeCode": "ABCD"
    },
    {
      "ratePeriods": [
        {
          "startDate": "2025-03-08",
          "endDate": "2025-03-08",
          "inventoryTypeRate": "90.00"
        }
      ],
      "inventoryTypeCode": "WXYZ"
    },
    {
      "ratePeriods": [
        {
          "startDate": "2025-03-09",
          "endDate": "2025-03-09",
          "inventoryTypeRate": "135.00"
        }
      ],
      "inventoryTypeCode": "WXYZ"
    }
  ]
}

jolt spec I tried

[
  {
    "operation": "shift",
    "spec": {
      "pricePlans": {
        "*": {
          "amountRules": {
            "*": {
              "period": {
                "start": "inventoryTypes[#3].ratePeriods[#2].startDate",
                "end": "inventoryTypes[#3].ratePeriods[#2].endDate"
              },
              "inventoryTypes": {
                "*": {
                  "0": {
                    "value": "inventoryTypes[#3].ratePeriods[#2].inventoryTypeRate"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

but this is giving me 2 block of ratePeriods but i need 4 in this case each containing both values "inventoryTypeRate" together it has to come in differently."inventoryTypeCode": "ABCD" im populating form a different part and working perefctly so that can be ignored here, this is a part of the json.

Share Improve this question edited Mar 11 at 20:03 Barbaros Özhan 65.5k11 gold badges36 silver badges61 bronze badges asked Mar 11 at 8:50 OptimizerOptimizer 2711 gold badge2 silver badges10 bronze badges 1
  • @Barbaros Özhan I updated the jolt I tried in the question. – Optimizer Commented Mar 11 at 13:22
Add a comment  | 

1 Answer 1

Reset to default 0

You'd better

  • using one more partition in such a way like &4_&2 instead of [#3] in which there's only one

  • looping through the arrays nested within the "inventoryTypes" object

such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*s": { //stands for "inventoryTypes" in order to be able to extract the literal "inventoryType"
                "*": {
                  "0": { //take from the first object of the array
                    "@3,period": {
                      "start|end": "&5_&3.&4.ratePeriods[#3].&"
                    },
                    "value": "&4_&2.&3.ratePeriods[#2].&(3,1)Rate"
                  },
                  "$": "&3_&1.&2.&(2,1)Code"
                }
              }
            }
          }
        }
      }
    }
  },
  {//get rid of the outermost wrappers
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&[]"
      }
    }
  }
]

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744806248a4594791.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信