[英]Transform json object with jq, transforming values with base64 decode
I'm working with a json object that looks like this:我正在使用看起来像这样的 json object:
{
"someattrinbute": "somevalue",
"data": {
"SOMENAME": "...",
"SOMEOTHERNAME": "...",
...
}
}
Where all the values in the "data" object are base64-encoded.其中“数据”object 中的所有值都是 base64 编码的。 I want to produce the same json, but with all the property values in the "data" object are base64-decoded.我想生成相同的 json,但“数据”object 中的所有属性值都是 base64 解码的。
I believe this would involve using "to_entries", "from_entries", and the "@base64d" function, but I can't see how to package this all together.我相信这将涉及使用“to_entries”、“from_entries”和“@base64d”function,但我看不出如何将 package 一起使用。
I'll be doing this in a bash shell script.我将在 bash shell 脚本中执行此操作。
Given example.json:给定示例。json:
{
"someattrinbute": "somevalue",
"data": {
"SOMENAME": "MTIz",
"SOMEOTHERNAME": "NDU2"
}
}
the invocation:调用:
$ jq '.data[] |= @base64d' example.json
produces:产生:
{
"someattrinbute": "somevalue",
"data": {
"SOMENAME": "123",
"SOMEOTHERNAME": "456"
}
}
map_values can be used for to apply the @base64d
function to each element of the object. map_values可用于将@base64d
function 应用于 object 的每个元素。
For example例如
jq '.data|map_values(@base64d)' example.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.