使用jq的JSON中的Concat 2字段 [英] Concat 2 fields in JSON using jq

查看:50
本文介绍了使用jq的JSON中的Concat 2字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jq重新格式化我的JSON.

I am using jq to reformat my JSON.

JSON字符串:

{"channel": "youtube", "profile_type": "video", "member_key": "hello"}

想要的输出:

{"channel" : "profile_type.youtube"}

我的命令:

echo '{"channel": "youtube", "profile_type": "video", "member_key": "hello"}' | jq -c '. | {channel: .profile_type + "." + .member_key}'

我知道下面的命令将字符串连接起来.但是它不能以与上面相同的逻辑工作:

I know that the command below concatenates the string. But it is not working in the same logic as above:

echo '{"channel": "youtube", "profile_type": "video", "member_key": "hello"}' | jq -c '.profile_type + "." + .member_key'

如何仅使用jq来获得结果?

How can I achieve my result using ONLY jq?

推荐答案

使用括号围绕字符串的连接代码:

Use parentheses around the string concatenation code:

echo '{"channel": "youtube", "profile_type": "video", "member_key": "hello"}' \
 | jq '{channel: (.profile_type + "." + .channel)}'

这篇关于使用jq的JSON中的Concat 2字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆