https://stedolan.github.io/jq/manual/
在线测试: https://jqplay.org/
一些小心得:
案例1
JSON:
{"hello":["a","b"]}
目标: 输出一个json, 把数组 hello
中的值连接起来
jq-expression:
.hello | join(",") | {tmp:.} | .greeting="Welcome to Serverless Workflow, " + .tmp | {payload:{ greeting: .greeting}}
输出:
{
"payload": {
"greeting": "Welcome to Serverless Workflow, a,b"
}
}
案例2
JSON:
{
"greeting": "John"
}
目标: 输出一个json, 把 greeting
的值进行修改
jq-expression:
.greeting="Welcome to Serverless Workflow, " + .greeting | {payload:{ greeting: .greeting}}
输出:
{
"payload": {
"greeting": "Welcome to Serverless Workflow, John"
}
}
案例3
JSON:
John
目标: 输出一个json, 把字符串包装在其中
jq-expression:
.greeting="Welcome to Serverless Workflow, " + . | {payload:{ greeting: .greeting}}
输出:
{
"payload": {
"greeting": "Welcome to Serverless Workflow, John"
}
}
网友评论