json - 数组子段中的 JOLT 转换布尔值
问题描述
我有一个 SAP Idoc,其中包含额外的客户特定字段作为 JSON
{
"E1EDL20": [
{
"VBELN": "1234567890",
"VSTEL": "ZO01",
"LGNUM": "123",
"NTGEW": "100.660",
"ANZPK": "00002",
"/XYZ/XYZ1234_E1EDL20": {
"ACTION": "POSTED",
"CONSIGNMENT": "12345678",
"FREIGHT_ORDER_EXTERNAL": "S123456789",
"IN_YARD": "X",
"IN_YARD_DATE": "20201123",
"IN_YARD_TIME": "100923"
},
"E1ADRM1": [
{
"PARTNER_Q": "LF",
"PARTNER_ID": "0000100000",
"/XYZ/XYZ1234_E1ADRM1": {
"SUPPLIER": "X"
}
},
{
"PARTNER_Q": "OSP",
"PARTNER_ID": "ZO01",
"/XYZ/XYZ1234_E1ADRM1": {
"SUPPLIER": "X"
}
}
]
}
]
}
然后我尝试删除根数组,重命名字段并将字符串类型转换为整数、双精度和布尔值,并将日期和时间字段连接到时间戳。这是我的规格。
[
// Our E1EDL20 array has only one entry -> remove array
{
"operation": "cardinality",
"spec": {
"E1EDL20": "ONE"
}
},
// Move all contained fields to root level and properly rename them
{
"operation": "shift",
"spec": {
"E1EDL20": {
"VBELN": "deliveryInternal",
"VSTEL": "receivingPoint",
"LGNUM": "warehouseNumber",
"NTGEW": "netWeight",
"ANZPK": "numberOfPackages",
"/XYZ/XYZ1234_E1EDL20": {
"ACTION": "action",
"CONSIGNMENT": "consignment",
"FREIGHT_ORDER_EXTERNAL": "freightOrderExternal",
// Rename Content of the field to Boolean String
"IN_YARD": {
"X": { "#true": "inYard" },
"*": { "#false": "inYard" }
},
"IN_YARD_DATE": "inYardDateTmp",
"IN_YARD_TIME": "inYardTimeTmp"
},
// Suppliers
"E1ADRM1": {
"*": {
"PARTNER_Q": "supplier[&1].type",
"PARTNER_ID": "supplier[&1].number",
"/XYZ/XYZ1234_E1ADRM1": {
"SUPPLIER": {
"X": { "#true": "supplier[&2].supplier" },
"*": { "#false": "supplier[&2].supplier" }
}
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
// Type conversions, String to Double or Integer
"netWeight": ["=toDouble", null],
"numberOfPackages": ["=toInteger", null],
// Type conversions, String to Boolean
"inYard": ["=toBoolean"],
"supplier": {
"*": {
"belomSupplier": ["=toBoolean"]
}
}
}
},
{
// Create Timestamp for inYardDate
"operation": "modify-default-beta",
"spec": {
"temp_DateYear": "=substring(@(1,inYardDateTmp),0,4)",
"temp_DateMonth": "=substring(@(1,inYardDateTmp),4,6)",
"temp_DateDay": "=substring(@(1,inYardDateTmp),6,8)",
"temp_TimeHours": "=substring(@(1,inYardTimeTmp),0,2)",
"temp_TimeMinutes": "=substring(@(1,inYardTimeTmp),2,4)",
"temp_TimeSeconds": "=substring(@(1,inYardTimeTmp),4,6)",
// Prior to this line, only temporary fields were created from substrings as preparation for the timestamp concatenateion
"inYardDate": "=concat(@(1,temp_DateYear),'-',@(1,temp_DateMonth),'-',@(1,temp_DateDay),'T',@(1,temp_TimeHours),':',@(1,temp_TimeMinutes),':',@(1,temp_prodTimeSeconds),'Z')"
}
},
{
// Remove temporary substring fields
"operation": "remove",
"spec": {
"temp_DateYear": "",
"temp_DateMonth": "",
"temp_DateDay": "",
"temp_TimeHours": "",
"temp_TimeMinutes": "",
"temp_TimeSeconds": "",
"inYardDateTmp": "",
"inYardTimeTmp": ""
}
}
]
我预计在 JOLT 转换后会有以下输出。
{
"deliveryInternal" : "1234567890",
"receivingPoint" : "ZO01",
"warehouseNumber" : "123",
"netWeight" : 100.66,
"numberOfPackages" : 2,
"action" : "POSTED",
"consignment" : "12345678",
"freightOrderExternal" : "S123456789",
"inYard" : true,
"inYardDate" : "2020-11-23T10:09:Z",
"supplier" : [ {
"type" : "LF",
"number" : "0000100000",
"supplier" : true
}, {
"type" : "OSP",
"number" : "ZO01",
"supplier" : true
} ]
}
但我得到以下输出。
{
"deliveryInternal" : "1234567890",
"receivingPoint" : "ZO01",
"warehouseNumber" : "123",
"netWeight" : 100.66,
"numberOfPackages" : 2,
"action" : "POSTED",
"consignment" : "12345678",
"freightOrderExternal" : "S123456789",
"inYard" : true,
"supplier" : [ {
"type" : "LF",
"number" : "0000100000"
}, {
"type" : "OSP",
"number" : "ZO01"
} ],
"inYardDate" : "2020-11-23T10:09:Z"
}
有谁知道如何解决这个问题?
解决方案
你只是想增加supplier: true
你的供应商吗?我看不出除此之外的任何其他差异。如果是这种情况,您可以将其添加到链规范的末尾:
{
// Add supplier = true to supplier elements
"operation": "shift",
"spec": {
"supplier": {
"*": {
"#true": "supplier[&1].supplier",
"*": "supplier[&1].&"
}
},
"*": "&"
}
}
推荐阅读
- python - 想要保持进程直到 subprocess.popen 中的 git 命令完成执行
- plsql - 运行 pl/sql 程序以查找前 10 个素数之和时出错
- c# - PdfSharp 不会更改文件系统信息
- typescript - 离子未捕获(承诺):[对象:对象]
- python - 把一个字符串变成一个元组
- mysql - SQL 计算一个表中发生在另一个表的开始日期和结束日期之间的日期
- scala - Intellij 中忽略的 JVM -ea 参数
- ios - React Native - panResponder 动画在 iOS 上不起作用
- python - 转换vti文件以使用python打开它
- php - composer-php 安装 laravel 失败