bash
可以发出脚本中的什么 shell 命令来有效地从 JSON 文件中的数字中去除所有小数位,例如:
[
{
"IMSKU": "1000001",
"AttributeID": 7332.0,
"Value": "McAfee Host Intrusion Prevention for Desktops safeguards your business against complex security threats that may otherwise be unintentionally introduced or allowed by desktops and laptops. Host Intrusion Prevention for Desktops is easy to deploy, configure, and manage.",
"Unit": null,
"StoredValue": null,
"StoredUnit": null,
"Name": "Marketing text",
"Format": "1",
"Position": "1",
"Group_Name": "Basic Specification",
"AGGroup_Position": 0.0,
"Product_Hierarchy": 15198001453.0
},
{
"IMSKU": "1000001",
"AttributeID": 7343.0,
"Value": "May 2013",
"Unit": null,
"StoredValue": null,
"StoredUnit": null,
"Name": "PI Date",
"Format": "1",
"Position": "1",
"Group_Name": "PI DATE",
"AGGroup_Position": 1.0,
"Product_Hierarchy": 15198001453.0
},
{
"IMSKU": "1000001",
"AttributeID": 7344.0,
"Value": "McAfee",
"Unit": null,
"StoredValue": "0.00",
"StoredUnit": null,
"Name": "Brand Name",
"Format": "3",
"Position": "1",
"Group_Name": "PRODUCT",
"AGGroup_Position": 2.0,
"Product_Hierarchy": 15198001453.0
}
]
以便
"AttributeID": 7344.0
会成为
"AttributeID": 7344
例如,等等。
只需通过身份过滤器运行它,
jq
将具有.0
小数的数字重新格式化为整数:如果有小数不为零的数字,并且您也想删除这些数字,请使用
这会将
floor
函数应用于数据中的所有数字,将它们向下舍入到最接近的整数。还要调查是否有字符串在最后的点后包含数字,并删除这些数字(和点):
受影响的条目仍然是字符串,不会转换为数字类型。