我需要连接多个JSON文件,因此
将其翻译为中文:将此转换为:
...
"tag" : "description"
}
]
[
{
"tag" : "description"
...
将其翻译为中文:将此转换为:
...
"tag" : "description"
},
{
"tag" : "description"
...
我需要将模式] [
替换为,
,但换行符让我很困扰...
我使用了几种方法,以下是其中一些:
sed
sed -i '/]/,/[/{s/./,/g}' file.json
but I get this error:
sed: -e expression #1, char 16: unterminated address regex
I tried to delete all the newlines following this example
sed -i ':a;N;$!ba;s/\n/ /g' file.json
and the output file has "^M". Although I modified this file in unix, I used the dos2unix command on this file but nothing happens. I tried then to include the special character "^M" on the search but with worse results
Perl (as proposed here)
perl -i -0pe 's/]\n[/\n,/' file.json
but I get this error:
Unmatched [ in regex; marked by <-- HERE in m/]\n[ <-- HERE / at -e line 1.
][
之间的JSON对象是从哪里来的?换句话说,您目前是如何合并这些文件的? - Windlejq
吗?它是专门用来处理JSON文件的。这个命令行就足够了:jq -c -s -r '[.[]|.[]]' file.json > result.json
- Casimir et Hippolyte