我有一个名为 new_file.json 的大文件,其中包含多个json,例如:
{ "ResourceRecordSets": [ { "Name": "XYZ.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-1219.buydmms-24.org." }, { "Value": "mms-1606.buydmms-08.co.uk." }, { "Value": "mms-516.buydmms-00.net." }, { "Value": "mms-458.buydmms-57.com." } ] }, { "Name": "XYZ.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "ABC.COM. 1 7200 900 1209600 86400" } ] }, { "Name": "bb.XYZ.", "Type": "CNAME", "SetIdentifier": "fix", "GeoLocation": { "ContinentCode": "EU" }, "TTL": 300, "ResourceRecords": [ { "Value": "abx.xyz.com" } ] }, { "Name": "bb.XYZ.", "Type": "CNAME", "SetIdentifier": "route to xms staging svc", "GeoLocation": { "CountryCode": "*" }, "TTL": 60, "ResourceRecords": [ { "Value": "xms-staging-xmssvc-1241009625.eu-west-1.elb.amazonbuy.com" } ] } ] }
{ "ResourceRecordSets": [ { "Name": "xyz.com.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-877.buydmms-45.net." }, { "Value": "mms-1168.buydmms-18.org." }, { "Value": "mms-375.buydmms-46.com." }, { "Value": "mms-1835.buydmms-37.co.uk." } ] }, { "Name": "xyz.com.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-877.buydmms-45.net. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] }, { "Name": "prod.xyz.com.", "Type": "CNAME", "SetIdentifier": "pointing to finclub", "Weight": 1, "TTL": 300, "ResourceRecords": [ { "Value": "indiv-finclub.elb.amazonbuy.com" } ] }, { "Name": "prod.xyz.com.", "Type": "CNAME", "SetIdentifier": "pointing to symentic", "Weight": 99, "TTL": 300, "ResourceRecords": [ { "Value": "some.com" } ] } ] }
{ "ResourceRecordSets": [ { "Name": "fun.org.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-352.buydmms-44.com." }, { "Value": "mms-1131.buydmms-13.org." }, { "Value": "mms-591.buydmms-09.net." }, { "Value": "mms-1997.buydmms-57.co.uk." } ] }, { "Name": "fun.org.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-352.buydmms-44.com. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] }, { "Name": "portal-junior.fun.org.", "Type": "CNAME", "TTL": 300, "ResourceRecords": [ { "Value": "portal.expressplay.com" } ] } ] }
{ "ResourceRecordSets": [ { "Name": "junior.fun.org.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-518.buydmms-00.net." }, { "Value": "mms-1447.buydmms-52.org." }, { "Value": "mms-499.buydmms-62.com." }, { "Value": "mms-1879.buydmms-42.co.uk." } ] }, { "Name": "junior.fun.org.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-518.buydmms-00.net. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] }, { "Name": "db.junior.fun.org.", "Type": "CNAME", "TTL": 300, "ResourceRecords": [ { "Value": "xms16-ap.crds.hurdle.com" } ] }, { "Name": "junior.junior.fun.org.", "Type": "CNAME", "ResourceRecords": [ { "Value": "This resource record set includes an attribute that is ummsupported on this Route 53 endpoint. Please commsider using a newer endpoint or a tool that does so." } ], "TrafficPolicyImmstanceId": "17b76444-85c2-4ec5-a16d-8611fa05ca82" } ] }
{ "ResourceRecordSets": [ { "Name": "junior.myjuniordmms.org.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-455.buydmms-56.com." }, { "Value": "mms-1381.buydmms-44.org." }, { "Value": "mms-741.buydmms-28.net." }, { "Value": "mms-1992.buydmms-57.co.uk." } ] }, { "Name": "junior.myjuniordmms.org.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-455.buydmms-56.com. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] } ] }
我想与一个有效的json制作相同的文件,可以通过在shell / bash中使用jq或其他方法来实现
答案 0 :(得分:1)
是的,可以。
命令:
cat new_file.json | jq -s '.[0] * .[1]'
输出:
{
"ResourceRecordSets": [
{
"Name": "xyz.com.",
"Type": "mms",
"TTL": 172800,
"ResourceRecords": [
{
"Value": "mms-877.buydmms-45.net."
},
{
"Value": "mms-1168.buydmms-18.org."
},
{
"Value": "mms-375.buydmms-46.com."
},
{
"Value": "mms-1835.buydmms-37.co.uk."
}
]
},
{
"Name": "xyz.com.",
"Type": "SOA",
"TTL": 900,
"ResourceRecords": [
{
"Value": "mms-877.buydmms-45.net. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400"
}
]
},
{
"Name": "prod.xyz.com.",
"Type": "CNAME",
"SetIdentifier": "pointing to finclub",
"Weight": 1,
"TTL": 300,
"ResourceRecords": [
{
"Value": "indiv-finclub.elb.amazonbuy.com"
}
]
},
{
"Name": "prod.xyz.com.",
"Type": "CNAME",
"SetIdentifier": "pointing to symentic",
"Weight": 99,
"TTL": 300,
"ResourceRecords": [
{
"Value": "some.com"
}
]
}
]
}
答案 1 :(得分:0)
仅使用unix / linux实用程序即可实现相同的目的:sed
和paste
:
bash $ cat new_file.json | sed '/^ *$/d' | paste -s -d, - | sed -E 's/(.*)/[\1]/'
sed
删除所有空白行paste
将所有输入行连接到逗号,
sed
在输入周围放置方括号