json - 如何在 JSONPath 中有条件地返回特定值?
问题描述
我有一个像这样的对象:
{
"content": {
"iteration_size": 1
}
}
我需要一个 JSONPath,null
如果 的值next_item
正好为 1,则返回,iteration_size
否则返回值。所以上面应该返回null
并且"iteration_size": 2
应该返回 2。这可能在 JSONPath 中吗?
我尝试过 的变体$.content[?(@.iteration_size == 1)].iteration_size
,但我尝试过的两位在线评估员甚至不同意我几次尝试的结果。
用例是 AWS Batch API,其中数组大小必须是null
2 到 10,000 之间的一个或一个数字。
解决方案
AWS Support 建议这是不可能的,我应该在 step 函数中使用一个分支。我最终替换了这个:
.next(batch_submit_job)
[…]
有了这个:
.next(
aws_stepfunctions.Choice(self, "check_maybe_array")
.when(
aws_stepfunctions.Condition.number_equals("$.content.iteration_size", 1),
single_batch_submit_job,
)
.otherwise(array_batch_submit_job)
.afterwards()
)
其中只有array_batch_submit_job
一个array_size
. 请注意 step 函数的其余部分如何最终包裹在最后一次next()
调用中而不是顶层。
推荐阅读
- ajax - ajax 请求后找不到类 - 10 月 cms
- modelica - 在 OpenModelica 中保存开始/初始猜测值并从文件中实现初始值
- scala - 如何组成一个零参数函数?
- javascript - nuxt.js 文件未定义,pugin 有问题
- php - 无法在 laravel 项目中导航页面
- sql - SQL SERVER 使用 Regex 模式生成数据
- javascript - 如何在表格中显示之前重新格式化日期
- amazon-s3 - 适用于 PHP 的 AWS 开发工具包,上传图像返回 500 内部服务器错误
- javascript - 如何在不使用 Javascript 下载的情况下打开 ical 事件?
- python - 为什么 torch.from_numpy 需要不同的字节顺序,而 matplotlib 不需要?