【发布时间】:2017-06-12 10:47:25
【问题描述】:
我实际上在Windows 10 环境下使用JQ1.5 来转换几个json 文件以导入MS SQL 数据库。部分数据格式为UNIX timestamp,我需要将这些数据转换为 ISO 8601 格式。
我实际用于数据转换的以下命令:
jq '
[
{ nid, title, nights, zone: .zones[0].title} +
(.sails[] | { sails_nid: .nid, arrival, departure } ) +
(.sails[].cabins[] |
{ cabintype: .cabinType.kindName,
cabinid: .cabinType.nid,
catalogPrice,
discountPrice,
discountPercentage,
currency
}
)
]
' C:\Import\dreamlines_details.json > C:\Import\import_sails.json
到达和离开是 Unix 时间格式的数据。
数据:
[
{
"nid": 434508,
"title": "Die schönsten Orte unserer Welt",
"nights": 121,
"zone": "Weltreise",
"sails_nid": 434516,
"arrival": 1525644000,
"departure": 1515193200,
"cabintype": "Innenkabine",
"cabinid": 379723,
"catalogPrice": 17879,
"discountPrice": 9519,
"discountPercentage": 0.4675876726886291,
"currency": "EUR"
},
{
"nid": 434508,
"title": "Die schönsten Orte unserer Welt",
"nights": 121,
"zone": "Weltreise",
"sails_nid": 434516,
"arrival": 1525644000,
"departure": 1515193200,
"cabintype": "Innenkabine",
"cabinid": 379730,
"catalogPrice": 18599,
"discountPrice": 10239,
"discountPercentage": 0.44948653153395346,
"currency": "EUR"
}
]
我尝试了内置运算符“todate”和“strftime”。但只得到解析错误。
【问题讨论】:
-
你应该发布带有关键数据的输入 json 片段
-
嗨 @RomanPerekhrest 添加了数据
-
您的代码和示例 json 不匹配。请考虑根据MCVE 简化您的代码和示例