gpt4 book ai didi

json - 尝试使用JQ处理json数据:Elasticsearch批量索引API

转载 作者:行者123 更新时间:2023-12-03 01:24:13 26 4
gpt4 key购买 nike

这个问题来自以下帖子:

Elasticsearch Bulk JSON Data
jq -c -r ".[]" C:\setting-es.json | while read line; do echo '{"index":{}}'; echo $line; done > bulk.json
上面的jq shell命令抛出错误“do循环中缺少语句主体”

我曾尝试更改语法,但仍然无法正常工作。我正在尝试编写一个shell脚本来为Elasticsearch的批量API转换以下数据:

[{
"codeId": "111",
"association": [{
"associationId": 123,
"businessUnitsAssociationId": 1,
"financialBusinessUnits": "DCS",
"businessApprovalLimit": [{
"businessApprovalLimitApprovalLimitId": 1,
"itemMinAmount": "0.00",
"itemMaxAmount": "0.00"
}, {
"businessApprovalLimitApprovalLimitId": 2,
"itemMinAmount": "0.00",
"itemMaxAmount": "0.00"
}, {
"businessApprovalLimitApprovalLimitId": 3,
"itemMinAmount": "0.00",
"itemMaxAmount": "0.00"
}]
}]
}]

我正在尝试将其转换为以下内容:
{"index":{}}
[{"codeId":"111","association":[{"associationId":123,"businessUnitsAssociationId":1,"financialBusinessUnits":"DCS","businessApprovalLimit":[{"businessApprovalLimitApprovalLimitId":1,"itemMinAmount":"0.00","itemMaxAmount":"0.00",},{"businessApprovalLimitApprovalLimitId":2,"itemMinAmount":"0.00","itemMaxAmount":"0.00",},{"businessApprovalLimitApprovalLimitId":3,"itemMinAmount":"0.00","itemMaxAmount":"0.00",}]}]


最佳答案

在纠正了无效的JSON之后(即在删除了两个多余的逗号之后),这是对修订后的问题的解答。

仍然不需要 shell 循环。

在bash或类似bash的提示下:

jq -c '.[] | ({"index":{}}, [.])'  input.json

在Powershell提示下,将jq程序放入文件中并使用 -f FILENAME选项调用jq可能会更容易。

关于json - 尝试使用JQ处理json数据:Elasticsearch批量索引API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58904838/

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