Select 个数组中的键,然后将其作为数组写入配置文件
Select keys within an array then write that out to a config file as an array
我正在努力解决以下问题。我想将下面的输出放入一个数组中,我可以将其保存为恒温器列表(我目前只有 1 个,但我想计划拥有 2 个)
jq '.thermostatList[] | {name, identifier}' test.json
{
"name": "Thermostat",
"identifier": "123456789"
}
我想要什么
cat ~/etc/ecobee.thermostats
{
"thermostats": [
{
"name": "Thermostat",
"identifier": 123456789
}
]
}
jq 可以吗?
谢谢
以thermostatList
为上下文map
:
jq '.thermostatList | {thermostats: map({name, identifier})}' test.json
{
"thermostats": [
{
"name": "Thermostat",
"identifier": 123456789
}
]
}
我正在努力解决以下问题。我想将下面的输出放入一个数组中,我可以将其保存为恒温器列表(我目前只有 1 个,但我想计划拥有 2 个)
jq '.thermostatList[] | {name, identifier}' test.json
{
"name": "Thermostat",
"identifier": "123456789"
}
我想要什么
cat ~/etc/ecobee.thermostats
{
"thermostats": [
{
"name": "Thermostat",
"identifier": 123456789
}
]
}
jq 可以吗?
谢谢
以thermostatList
为上下文map
:
jq '.thermostatList | {thermostats: map({name, identifier})}' test.json
{
"thermostats": [
{
"name": "Thermostat",
"identifier": 123456789
}
]
}