gpt4 book ai didi

json - 使用 JQ 将所有 json 键转换为小写

转载 作者:行者123 更新时间:2023-12-04 17:07:25 25 4
gpt4 key购买 nike

我希望将带有数组的 JSON 文件摄取到我的数据库中。带有数组项的 json 文件如下:-

   {
"campaignId": "11067182",
"campaignName": "11067182",
"channelId": "%pxbid_universal_site_id=!;",
"channelName": "%pxbid_universal_site_id=!;",
"placementId": "%epid!",
"placementName": "%epid!",
"publisherId": "%esid!",
"publisherName": "%esid!",
"hitDate": "2017-03-23",
"lowRiskImpressions": "61485",
"lowRiskPct": "64.5295",
"moderateRiskImpressions": "1887",
"moderateRiskPct": "1.9804",
"highRiskImpressions": "43",
"highRiskPct": "0.0451",
"veryHighRiskImpressions": "860",
"veryHighRiskPct": "0.9026",
"totalRated": "95274",
"unrated": "8",
"unratedPct": "0.0084",
"visibleCount": "64283",
"pctVisible": "67.4660",
"invisibleCount": "30999",
"totalImpressions": "95282"
}
{
"campaignId": "11067182",
"campaignName": "11067182",
"channelId": "%pxbid_universal_site_id=!;",
"channelName": "%pxbid_universal_site_id=!;",
"placementId": "%epid!",
"placementName": "%epid!",
"publisherId": "%esid!",
"publisherName": "%esid!",
"hitDate": "2017-03-22",
"lowRiskImpressions": "17929",
"lowRiskPct": "52.9379",
"moderateRiskImpressions": "1872",
"moderateRiskPct": "5.5273",
"highRiskImpressions": "9",
"highRiskPct": "0.0266",
"veryHighRiskImpressions": "139",
"veryHighRiskPct": "0.4104",
"totalRated": "33850",
"unrated": "18",
"unratedPct": "0.0531",
"visibleCount": "19967",
"pctVisible": "58.9554",
"invisibleCount": "13901",
"totalImpressions": "33868"
}

有没有办法重现相同的数组,但使用 jq 将键转换为小写字母?

最佳答案

简短的回答是肯定的,假设您指的是 ASCII 字符。

在您提到的特定情况下,您可以使用此过滤器:

with_entries( .key |= ascii_downcase )

但是,您提到了数组。如果您指的是 JSON 数组,则必须修改上述内容。

一种可能性是使用 walk/1 ,但你的 jq 可能没有。如果您想使用 walk/1 ,你可以通过谷歌搜索在 jq 中找到它的定义:jq def walk

以下是它的使用方法:
walk(if type=="object" then with_entries(.key|=ascii_downcase) else . end)

关于json - 使用 JQ 将所有 json 键转换为小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43038453/

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