使用 JOLT 进行数组映射

问题描述

第一次 JOLT 用户尝试将数组重组为类似的多级数组。 stackoverflow 要求更少的代码和更多的单词,所以我希望这个额外的句子涵盖了这一点。

输入 JSON

  {
    "studentIdentifier": "453089029","studentRegistrationNumber": "753082022","parentIdentifier": "1001142760","parentFamilyName": "lastname1001142760","relationshipIdentifier": "1001142762","relationshipToStudent": "Mother"
  },{
    "studentIdentifier": "453089193","studentRegistrationNumber": "753082123","relationshipIdentifier": "1001159585","relationshipToStudent": "Mother"
  }
]

所需的 JSON 输出

{
  "carer" : {
    "relationships" : [ {
      "relationshipIdentifier" : "1001142762","relationshipToStudent" : "Mother","student" : {
        "studentIdentifier" : "453089029","studentRegistrationNumber" : "753082022"
      }
    },{
      "relationshipIdentifier" : "1001159585","student" : {
        "studentIdentifier" : "453089193","studentRegistrationNumber" : "753082123"
      }
    } ],"parentIdentifier" : "1001142760","parentFamilyName" : "lastname1001142760"
  }
}

目前为止的 JOLT 规范

[
  {
    "operation": "shift","spec": {
      "*": {
        "@": "carer.relationships[].student","parent*": "carer.&"
      }
    }
  },{
    "operation": "cardinality","spec": {
      "*": {
        "parent*": "ONE"
      }
    }
  },{
    "operation": "remove","spec": {
      "carer": {
        "relationships": {
          "*": {
            "student": {
              "parent*": "","relationshiP*": ""
            }
          }
        }
      }
    }
  }
]

目前得到这个结果

{
  "carer" : {
    "relationships" : [ {
      "student" : {
        "studentIdentifier" : "453089029",{
      "student" : {
        "studentIdentifier" : "453089193","parentFamilyName" : "lastname1001142760"
  }
}

如何在正确的级别映射缺失的关系*字段或有更好的方法

解决方法

规格:

[
  {
    "operation": "shift","spec": {
      "*": {
        "*": "&","student*": "carer.relationships[&1].student.&","relationship*": "carer.relationships[&1].&"
      }
    }
  },{
    "operation": "cardinality","spec": {
      "parent*": "ONE"
    }
  }
]