【问题标题】:Array mapping with JOLT使用 JOLT 进行数组映射
【发布时间】:2020-12-23 09:24:34
【问题描述】:

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

输入 JSON

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

所需的 JSON 输出

{
  "carer" : {
    "relationships" : [ {
      "relationshipIdentifier" : "1001142762",
      "relationshipToStudent" : "Mother",
      "student" : {
        "studentIdentifier" : "453089029",
        "studentRegistrationNumber" : "753082022"
      }
    }, {
      "relationshipIdentifier" : "1001159585",
      "relationshipToStudent" : "Mother",
      "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",
        "studentRegistrationNumber" : "753082022"
      }
    }, {
      "student" : {
        "studentIdentifier" : "453089193",
        "studentRegistrationNumber" : "753082123"
      }
    } ],
    "parentIdentifier" : "1001142760",
    "parentFamilyName" : "lastname1001142760"
  }
}

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

【问题讨论】:

    标签: jolt


    【解决方案1】:

    规格:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-30
      • 1970-01-01
      • 2017-04-26
      • 2019-02-15
      • 2018-09-21
      • 2017-09-20
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多