json - 从 json 文件批量 curl -d
问题描述
我有一个 json 文件,我想将每个对象传递给 curl -d 命令:
[
{
"number":"+336770002979",
"message":"La plupart\ntest",
"sender":"BEcompany",
"date": 1539286620000
},
{
"number":"+336600000780",
"message":"La plupart\ntest",
"sender":"BEcompany",
"date": 1539286620000
},
...
]
现在我试过这个
curl -X POST \
-H "X-Primotexto-ApiKey: 784155eed9d0a4d1ffdb67466" \
-H "Content-Type: application/json" \
-d @json.json \
https://api.primotexto.com/v2/notification/messages/send;
但它只读取第一个对象。
编辑[...]
由于您的评论,我修复了json 和 curl 命令。
解决方案
您可以使用jq -c .[]
将文件拆分为每行一个数组元素,然后从那里获取它。
jq -c .[] json.json |
while IFS= read -r fragment; do
curl -options -etc -d "$fragment" "http://url"
done
推荐阅读
- java - 工具栏菜单显示,但在实现片段时不可点击
- c++ - 如何禁用调试控制台在我的代码中显示文件地址?
- jquery - 在移动网站上滚动时,汉堡下拉导航栏不可见
- bash - 从 MySQL 读取的嵌套 while 循环中的 IFS 的 BASH 问题
- unit-testing - 为什么 JEST 模拟模块的异步函数不需要异步或断言或解析
- python - 将 DistributedMatrix 转换为 Scipy 稀疏或 Numpy 数组
- c - 我的 for 循环有什么问题?当我在 C 中的字母猜谜游戏中只输入 1 个输入时,它转了 2 次
- html - 使用图像作为可点击的锚链接
- apache-spark - 对于 Spark 结构化流应用程序,将日志流式传输到 CloudWatch Logs 的最佳方式是什么?
- excel - 禁止来自 Worksheet.BeforeDoubleClick 事件的保存更改提示