JOLT 变换数组
JOLT Transform Arrays
我目前有点卡住了,我需要使用 JOLT 来转换 JSON,但是对于我来说,我无法让数据/结构与我一起工作。
我需要转换以下数据集:
{
"policynumber": "12344",
"registrationnumber": "TST001",
"idnumber": "1234567890",
"policyholder": "Tst Me",
"policyfromdate": "2021-10-11",
"policytodate": "2021-10-31",
"ispolicyvalid": "Yes",
"policyproductcode": "TST111",
"policyproductdescription": "New Product",
"item_parent_section": "Risk",
"item_subsection_extension": "Risk2",
"item_original_start_date": "2021-10-11",
"item_status": "Active",
"item_sum_insured": "5000",
"item_description": "Personal Effects",
"item_asset_no": "ALL0002"
}
期望的结果应该是这样的:
{
"policyNumber": "12344",
"registrationNumber": "TST001",
"idNumber": "1234567890",
"policyholder": "Tst Me",
"policyFromDate": "2021-10-11",
"policyToDate": "2021-10-31",
"isPolicyValid": "Yes",
"policyProductCode": "TST111",
"policyProductDescription": "New Product",
"riskCategories": {
"item_parent_section": "Risk",
"item_subsection_extension": "Risk2",
"riskItemAllRisk": [
{
"item_status": "Active",
"item_description": "Personal Effects",
"item_sum_insured": "5000",
"item_original_start_date": "2021-10-11",
"item_asset_no": "ALL0002"
}
]
}
}
我可能在我想要的结果中犯了错误,但基本上,“riskItemAllRisk”部分需要在一个数组中。
我正在处理的 JOLT 转换是:
[
{
"operation": "shift",
"spec": {
"policynumber": "policyNumber",
"registrationnumber": "registrationNumber",
"idnumber": "idNumber",
"policyholder": "policyholder",
"policyfromdate": "policyFromDate",
"policytodate": "policyToDate",
"ispolicyvalid": "isPolicyValid",
"policyproductcode": "policyProductCode",
"policyproductdescription": "policyProductDescription"
}
},
{
"operation": "default",
"spec": {
"riskCategories": {
"item_parent_section": "itemparentsection",
"item_subsection_extension": "itemsubsectionextension"
}
}
},
{
"operation": "default",
"spec": {
"riskItemAllRisk[]": {
"0": {
"item_original_start_date": "2021-10-11",
"item_status": "item_status",
"item_sum_insured": "item_sum_insured",
"item_description": "item_description",
"item_asset_no": "item_asset_no"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"idNumber": "=toString"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"itemsuminsured": "=toString"
}
}
]
为糟糕的代码道歉,但这对我来说是第一次。
谢谢。
一个移位转换就足够了,例如
[
{
"operation": "shift",
"spec": {
"policynumber": "&",
"registrationnumber": "&",
"idnumber": "&",
"policyholder": "&",
"policyfromdate": "&",
"policytodate": "&",
"ispolicyvalid": "&",
"policyproductcode": "&",
"policyproductdescription": "&",
"item_parent_section": "riskCategories.&",
"item_subsection_extension": "riskCategories.&",
"*": "riskCategories.riskItemAllRisk[0].&"
}
}
]
其中 item_parent_section
和 item_subsection_extension
属性的值首先由 riskCategories
限定,数组的其余元素由 riskCategories.riskItemAllRisk[0]
限定
我目前有点卡住了,我需要使用 JOLT 来转换 JSON,但是对于我来说,我无法让数据/结构与我一起工作。
我需要转换以下数据集:
{
"policynumber": "12344",
"registrationnumber": "TST001",
"idnumber": "1234567890",
"policyholder": "Tst Me",
"policyfromdate": "2021-10-11",
"policytodate": "2021-10-31",
"ispolicyvalid": "Yes",
"policyproductcode": "TST111",
"policyproductdescription": "New Product",
"item_parent_section": "Risk",
"item_subsection_extension": "Risk2",
"item_original_start_date": "2021-10-11",
"item_status": "Active",
"item_sum_insured": "5000",
"item_description": "Personal Effects",
"item_asset_no": "ALL0002"
}
期望的结果应该是这样的:
{
"policyNumber": "12344",
"registrationNumber": "TST001",
"idNumber": "1234567890",
"policyholder": "Tst Me",
"policyFromDate": "2021-10-11",
"policyToDate": "2021-10-31",
"isPolicyValid": "Yes",
"policyProductCode": "TST111",
"policyProductDescription": "New Product",
"riskCategories": {
"item_parent_section": "Risk",
"item_subsection_extension": "Risk2",
"riskItemAllRisk": [
{
"item_status": "Active",
"item_description": "Personal Effects",
"item_sum_insured": "5000",
"item_original_start_date": "2021-10-11",
"item_asset_no": "ALL0002"
}
]
}
}
我可能在我想要的结果中犯了错误,但基本上,“riskItemAllRisk”部分需要在一个数组中。
我正在处理的 JOLT 转换是:
[
{
"operation": "shift",
"spec": {
"policynumber": "policyNumber",
"registrationnumber": "registrationNumber",
"idnumber": "idNumber",
"policyholder": "policyholder",
"policyfromdate": "policyFromDate",
"policytodate": "policyToDate",
"ispolicyvalid": "isPolicyValid",
"policyproductcode": "policyProductCode",
"policyproductdescription": "policyProductDescription"
}
},
{
"operation": "default",
"spec": {
"riskCategories": {
"item_parent_section": "itemparentsection",
"item_subsection_extension": "itemsubsectionextension"
}
}
},
{
"operation": "default",
"spec": {
"riskItemAllRisk[]": {
"0": {
"item_original_start_date": "2021-10-11",
"item_status": "item_status",
"item_sum_insured": "item_sum_insured",
"item_description": "item_description",
"item_asset_no": "item_asset_no"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"idNumber": "=toString"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"itemsuminsured": "=toString"
}
}
]
为糟糕的代码道歉,但这对我来说是第一次。
谢谢。
一个移位转换就足够了,例如
[
{
"operation": "shift",
"spec": {
"policynumber": "&",
"registrationnumber": "&",
"idnumber": "&",
"policyholder": "&",
"policyfromdate": "&",
"policytodate": "&",
"ispolicyvalid": "&",
"policyproductcode": "&",
"policyproductdescription": "&",
"item_parent_section": "riskCategories.&",
"item_subsection_extension": "riskCategories.&",
"*": "riskCategories.riskItemAllRisk[0].&"
}
}
]
其中 item_parent_section
和 item_subsection_extension
属性的值首先由 riskCategories
限定,数组的其余元素由 riskCategories.riskItemAllRisk[0]