验证一些键的值是否在有效负载中。

huangapple go评论53阅读模式
英文:

verify if the value of some keys are in the payload

问题

{
"money": 0.22,
"perMinute": null,
"perSession": null
}

英文:

I have this input:

[
  {
    "building": 222,
    "default": {
      "money": 0.22,
      "perHour": null
    },
    "appPricing": [
      {
        "pricing": {
          "money": 1.25,
          "perHour": null
        },
        "schedules": [
          {
            "daysOfWeek": [
              "FRIDAY",
              "MONDAY"
            ],
            "end": "21:59:00",
            "start": "08:00:00"
          },
          {
            "days": [
              "TUESDAY",
              "WEDNESDAY",
              "THURSDAY"
            ],
            "end": "15:59:00",
            "start": "11:00:00"
          }
        ]
      }
    ]
  }
]

And I want to filter after a specific day, a specific end time, and a start time.
Here is the output:

{ 
  "money": 0.22, 
  "perMinute": null, 
  "perSession": null
} 

Thanks And I want to filter after a specific day, a specific end time, and a start time.

答案1

得分: 0

我假设你正试图根据时间表筛选定价,并在找不到定价时返回默认定价。关键是内部筛选器返回布尔条件,我已使用isEmpty!运算符进行了相同处理。

然而,我看到输出与输入之间存在差异。例如,输出中的perMinute和perSession字段。因此,请使用以下脚本作为起点,根据您的要求进行扩展/修改脚本。

希望这有所帮助!

英文:

I assume you are trying to filter pricing based on schedules and return default pricing in case no pricing found. The key is the internal filter to return the boolean condition, I have used isEmpty with ! operator for the same.

However, I see there is a difference in the output vs the input. For example, perMinute and perSession fields in output. So please use the below script as starting point, and extend/modify the script according to your requirements.

Hope this helps!

%dw 2.0
output application/json
var inp = {
    day: "THURSDAY",
    endTime: "16:59:00",
    startTime: "11:00:00"
}

fun matchSchedules (schedules) = 
    !isEmpty (schedules filter (($.daysOfWeek contains inp.day)
                    and $.endTime == inp.endTime
                    and $.startTime == inp.startTime))
---
((payload[0].appPricing filter ((price) -> matchSchedules(price.schedules)))[0].pricing) default payload[0]."default"

huangapple
  • 本文由 发表于 2023年8月10日 17:25:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定