gpt4 book ai didi

json - JQ键映射名称为大写并删除空格

转载 作者:行者123 更新时间:2023-12-05 08:50:22 26 4
gpt4 key购买 nike

我在 bash 脚本中工作,我必须使用 jq 自定义一个 JSON obj。我有:

[
{
"NC dn": "DC=company,DC=org",
"DSA objectGUID": "df9e8712-98c5-42e4-a020-2e5218404e51",
"last attempt time": "Wed Jun 10 15:27:42 2020 CEST",
"last attempt message": "was successful",
"consecutive failures": 0,
"last success": "Wed Jun 10 15:27:42 2020 CEST",
"NTDS DN": "CN=NTDS Settings,CN=STEN0002-R2,CN=Servers,CN=TENGIZ,CN=Sites,CN=Configuration,DC=company,DC=org",
"is deleted": false,
"DSA": "TENGIZ\\STEN0002-R2"
},
{
"NC dn": "DC=company,DC=org",
"DSA objectGUID": "d5d168fd-5fc3-4afc-9acc-32c7f10d14a2",
"last attempt time": "Wed Jun 10 15:27:42 2020 CEST",
"last attempt message": "was successful",
"consecutive failures": 0,
"last success": "Wed Jun 10 15:27:42 2020 CEST",
"NTDS DN": "CN=NTDS Settings,CN=SCGPN0002-R2,CN=Servers,CN=POINTE-NOIRE,CN=Sites,CN=Configuration,DC=company,DC=org",
"is deleted": false,
"DSA": "POINTE-NOIRE\\SCGPN0002-R2"
}
]

但我需要所有没有空格的键和大写的 {#JSON_KEY} 加上 CONSECUTIVE_FAILURES 值和 IS_DELETED 值与“”:

[
{
"{#NC_DN}": "DC=domain,DC=org",
"{#DSA_OBJECTGUID}": "df9e8712-98c5-42e4-a020-2e5218404e51",
"{#LAST_ATTEMPT_TIME}": "Wed Jun 10 15:27:42 2020 CEST",
"{#LAST_ATTEMPT_MESSAGE}": "was successful",
"{#CONSECUTIVE_FAILURES}": "0",
"{#LAST_SUCCESS}": "Wed Jun 10 15:27:42 2020 CEST",
"{#NTDS_DN}": "CN=NTDS Settings,CN=STEN0002-R2,CN=Servers,CN=TENGIZ,CN=Sites,CN=Configuration,DC=domain,DC=org",
"{#IS_DELETED}": "false",
"{#DSA}": "TENGIZ\\STEN0002-R2"
},
{
"{#NC_DN}": "DC=domain,DC=org",
"{#DSA_OBJECTGUID}": "d5d168fd-5fc3-4afc-9acc-32c7f10d14a2",
"{#LAST_ATTEMPT_TIME}": "Wed Jun 10 15:27:42 2020 CEST",
"{#LAST_ATTEMPT_MESSAGE}": "was successful",
"{#CONSECUTIVE_FAILURES}": "0",
"{#LAST_SUCCESS}": "Wed Jun 10 15:27:42 2020 CEST",
"{#NTDS_DN}": "CN=NTDS Settings,CN=SCGPN0002,CN=Servers,CN=NOIRE,CN=Sites,CN=Configuration,DC=domain,DC=org",
"{#IS_DELETED}": "false",
"{#DSA}": "POINTE-NOIRE\\SCGPN0002-R2"
}
]

提前致谢

最佳答案

下面没有walk的开销就满足了要求:

map(with_entries( .key |= ( gsub( " "; "_")
| ascii_upcase
| "{#\(.)}" )
| .value |= tostring))

警告

顾名思义,ascii_upcase 仅大写 ASCII 字符。

关于json - JQ键映射名称为大写并删除空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62312365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com