如何保留一级对象并仅提取其子密钥之一? [英] How to keep one level of object and extract one of its sub-key only?
本文介绍了如何保留一级对象并仅提取其子密钥之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 terraform 状态 json 输出并希望对其进行一些转换.
I'm playing a bit with terraform state json output and want to transform it a bit.
鉴于从 terraform 发出的输入:
Given that input issued from terraform:
{
"cost": {
"sensitive": false,
"value": "123"
},
"test_id": {
"sensitive": false,
"value": "6610758455459338306"
}
}
如何将其转换为对我的应用程序有用的东西,如下所示:
How do i convert it to something usefull for my application like bellow:
{
"cost": "123",
"test_id": "6610758455459338306"
}
我尝试使用 from_entries
、with_entries
,但我完全是个菜鸟
I tried to play with from_entries
, with_entries
but i'm a complete noob at it
推荐答案
您正在寻找 map_values
.它的工作方式与 map
类似,但不会将对象输入转换为数组.
You're looking for map_values
. It works just like map
, but doesn't convert an object input to an array.
map_values(.value)
这篇关于如何保留一级对象并仅提取其子密钥之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文