json - 如何将动态值传递给具有重复字段的 JSON
问题描述
我有一个用例,我必须批量发送 REST 请求。
JSON 文件:emp.json
[
{
"field": {
"empID": "sapid",
"location": "India"
}
}
]
我的外壳脚本:
func emp_details
{
START=1
END=1000000
CURRENT=1
while [ $END -gt $CURRENT ];
do
CURRENT=$((CURRENT+1))
cat emp.json | jq --arg new "$CURRENT" '.[].field.empID |= $new' > temp.json
cat temp.json
curl <REST Server URL with temp.json as input> "Content-Type: application/json" -d @temp.json
done
}
上面的 json 和脚本正在工作。我能够正确发送请求。我正在寻找一种在触发 CURL 之前准备具有多个 empID 的 json 文件的方法。
例如:
[
{
"field": {
"empID": "sapid",
"location": "India",
}
},
{
"field": {
"empID": "sapid",
"location": "India",
}
},
{
"field": {
"empID": "sapid",
"location": "India",
}
}
]
但我不确定如何遍历每个单独的 empID 字段并将其值替换为动态 CURRENT 值。
任何帮助深表感谢
解决方案
推荐阅读
- javascript - 如何在javascript中的对象数组下获取值重复的计数
- javascript - 将 Javascript 转换为 Typescript。我构建的文件没有在我预期的地方结束
- laravel - Laravel 电子邮件验证 5.7
- javascript - 有没有办法只包含页面中需要的部分 JS 库?
- javascript - 为什么关闭打印预览后我的打印预览元素不隐藏?
- android - Flutter - 英雄动画内存密集吗?
- here-api - HERE-API:如果禁用时间感知功能,则使用什么日期时间?
- selenium - Selenium:使用 selenium 将文件上传到谷歌驱动器
- php - Prestashop后台批量产品导入
- javascript - 异步/等待嵌套在循环中