
如题,有一个 json 文件,
[ { "id": 0001, "name": "Zhang.San_123456", "email": { "qqmail": "[email protected]", "163mail": "[email protected]" }, "Address": { "Province": "Guangdong", "City": "Zhanjiang", "Country": "Xuwen" } }, { "id": 0002, "name": "Li.Si_123456", "email": { "qqmail": "[email protected]", "163mail": "[email protected]" }, "Address": { "Province": "Sichuan", "City": "Yibin", "Country": "Jiang'an" } }, { "id": 0003, "name": "Wang.Wu_123456", "email": { "qqmail": "[email protected]", "163mail": "[email protected]" }, "Address": { "Province": "Shanxi", "City": "Taiyuan", "Country": "Qingxu" } } ] 我想获取里面 name 字段为 Li.Si_123456 的一部分,返回时移除 email 里的 163mail ,返回内容如下:
[ { "id": 0002, "name": "Li.Si_123456", "url": "http://xxx.com", "qqmail": "[email protected]", "Address": { "Province": "Sichuan", "City": "Yibin", "Country": "Jiang'an" } } ] 请教一下这个使用 jq 处理应该怎么写呢,有大佬能指教一下吗?谢谢了^^
1 0ZXYDDu796nVCFxq 2021-12-12 22:07:11 +08:00 via Android |
3 Ryanjie OP 解决方法: 1. 获取里面 name 字段为 Li.Si_123456 的一部分:`jq --arg NAME ${UserName} '.[] | select(.name==$NAME)'` 2. 返回时移除 email 里的 163mail: `map({id, name, url, qqmail: .email.qqmail,...})` |