英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论