gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
输入为一个字符串变量jsonstr,jsonstr包含以下内容,通过shell获取jsonstr中…
- User
- Assistant
To extract the
idcorresponding tologinNameaszhangsanfrom thejsonstrusing a shell command, you can utilize tools likejq, which is a lightweight and flexible command-line JSON processor. Here is a command you can use:echo 'jsonstr' | jq -r '.data[] | select(.loginName == "zhangsan") | .id'Replace
jsonstrwith your actual JSON string. This command breaks down as follows:echo 'jsonstr': Outputs the JSON string.jq -r: Invokesjqwith the-rflag to output raw data.'.data[] | select(.loginName == "zhangsan") | .id': Processes thejsonstrto filter objects in thedataarray whereloginNameiszhangsanand extracts theid.