使用How do I use a shell-script as Chrome Native Messaging host application上的代码作为模板,并给出文件file.json,该文件包含
{"text":"abc"}遵循Iterate over json with jq和jq documentation上的代码
$ cat file.json | jq --raw-output '.text'输出
abc我不确定如何在此Answer中合并模式
while read -r id name date; do
echo "Do whatever with ${id} ${name} ${date}"
done< <(api-producing-json | jq --raw-output '.newList[] | "\(.id) \(.name) \(.create.date)"')添加到前一个答案的模板中,以便使用jq从循环内的JSON捕获单个属性"text" (abc),以便能够将该文本传递给另一个系统调用,然后将消息printf发送到客户端。
我们想要实现的是
json=$(<bash program> <captured JSON property>)
message='{"message": "'$json'"}'其中{"text":"abc"}从客户端(Chromium应用程序)发送到本地消息传递主机。
如何在前一个Answer的代码中使用jq来将JSON属性作为变量获取?
发布于 2018-01-23 05:01:40
假设file.json包含如上所述的JSON,我相信您需要的是:
json=$(jq '{message: .}' file.json)如果您然后使用echo "$json",结果将是:
{
"message": {
"text": "abc"
}
}https://stackoverflow.com/questions/48385086
复制相似问题