base64 一般会默认安装,可以进行 base64 编码和解码。
jq 可以对json进行解析、选择、格式化、高亮等,需要通过 apt-get install jq
进行安装。
测试数据
① 原始数据
eyJuYW1lIjoiNWJDUDVwaU8iLCJhZ2UiOjI0LCJDb250YWN0Ijp7InRlbCI6IjE4NzMzMzMzMzMzIiwicXEiOiI1NTU1NTU1NTUifSwiZnJpZW5kcyI6W3sibmFtZSI6IjViQ1A2SXF4IiwiYWdlIjoyMn0seyJuYW1lIjoiNWJDUDZJdTUiLCJhZ2UiOjI0fV19
将原始数据保存到 test.json
文件中。
② Bsee64 解码之后
1 | { |
③ json 字段解码之后
1 | { |
bass64
简述
1 |
|
测试 1
1 | cat test.json | base64 -d |
结果 1
{"name":"5bCP5piO","age":24,"Contact":{"tel":"18733333333","qq":"555555555"},"friends":[{"name":"5bCP6Iqx","age":22},{"name":"5bCP6Iu5","age":24}]}
jq
格式化输出json
1 | cat test.json | base64 -d | jq "." |
结果
{
"name":"5bCP5piO",
"age":24,
"Contact":{
"tel":"18733333333",
"qq":"555555555"
},
"friends":[
{
"name":"5bCP6Iqx",
"age":22
},
{
"name":"5bCP6Iu5",
"age":24
}
]
}
1 | cat test.json | base64 -d | jq ".name" # "5bCP5piO" |
1 | cat test.json | base64 -d | jq ".friends[] | {friend_name: .name, friend_age: .age}" |
{
"friend_age": 22,
"friend_name": "5bCP6Iqx"
}
{
"friend_age": 24,
"friend_name": "5bCP6Iu5"
}
1 | cat test.json | base64 -d | jq "[ .friends[] | {friend_name: .name, friend_age: .age} ]" |
[
{
"friend_age": 22,
"friend_name": "5bCP6Iqx"
},
{
"friend_age": 24,
"friend_name": "5bCP6Iu5"
}
]