Aru*_*rul 3 shell base64 json decode
我有一个JSON,我需要通过特定的键提取base64编码的值并将其解码。
JSON具有以下结构:
[
{
"LockIndex": 0,
"Key": "Arul/key1",
"Flags": 0,
"Value": "MzAKCg==",
"CreateIndex": 369,
"ModifyIndex": 554
}
]
Run Code Online (Sandbox Code Playgroud)
在上面的JSON中,我只需要提取"Value":"MzAKCg=="并解码base64编码的"MzAKCg=="值即可。我想使用shell脚本执行此操作。
请协助。
mpk*_*uth 17
jq 最近增加了对 base64 编码和解码的支持
https://stedolan.github.io/jq/manual/#Formatstringsandescaping
@base64:
按照 RFC 4648 的规定,输入将转换为 base64。
@base64d:
@base64 的反函数,输入按照 RFC 4648 的规定进行解码。注意:如果解码的字符串不是 UTF-8,则结果未定义。
对于您的数据,命令将是
jq -r 'map(.Value | @base64d)' < file.json
Run Code Online (Sandbox Code Playgroud)
https://github.com/stedolan/jq/issues/47
它尚未发布,但您可以安装最新的开发版本来使用它。
brew reinstall --HEAD jq
Run Code Online (Sandbox Code Playgroud)
一旦 jq 的下一个版本发布,您就可以切换回最新的稳定版本。
jq -r '.[].Value' < file.json | base64 --decode
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3609 次 |
| 最近记录: |