规范中的JOLT变换数组索引问题

时间:2019-07-10 20:29:12

标签: jolt

如果输入中有集合,则以数组形式出现。如果缺少值,我将使用'modify-default-beta'写入默认值。 我唯一遇到的问题是FacTie正在生成多个,因为这不是我所期望的。

使用功能数组输入Json:

    {
  "type": "Collection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "coordinates": [
          121.63646666666666,
          29.10262638888889
        ]
      },
      "properties": {
        "clientId": "1123",
        "category": "44500",
        "datetime_created": " 2018-11-29 10:48:43",
        "facTieSk": "-1"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "coordinates": [
          121.63646666666666,
          29.10262638888889
        ]
      },
      "properties": {
        "clientId": "1124",
        "category": "44500",
        "datetime_created": " 2018-11-29 10:48:43",
        "facTieSk": "-1"
      }
    }
  ]
}

规格:

[
  {
    "operation": "shift",
    "spec": {
      "features": {
        "*": {
          "properties": {
            "@(1,type)": {
              "Feature": {
                "@(3,clientId)": "Composite[&4].FacComp.Fac.SysSource",
                "@(3,geometry)": {
                  "@coordinates": {
                    "*": "Composite[&6].FacComp.geometry.coordinates[]"
                  }
                },
                "@(2,category)": "Composite[&4].FacComp.Fac.Category",
                "@(2,datetime_created)": ["Composite[&4].FacComp.Fac.DatetimeCreated", "Composite[&4].FacComp.FacTie[&4].DatetimeCreated"],
                "@(2,facTieSk)": "Composite[&4].FacComp.FacTie[&4].FacTieSk"
              }
            }
          }
        }
      }
    }
        },
  {
    "operation": "modify-default-beta",
    "spec": {
      "Composite": {
        "*": {
          "FacComp?": {
            "Fac": {
              "FacSk": "-1",
              "CoordBasis": "2"
            },
            "FacTie": {
              "*": {
                "FacTieSk": "-1",
                "TieFromSk": "-1",
                "TieToSk": "-1",
                "TieToEntity": "FAC"
              }
            }
          }
        }
      }
    }
        }
    ]

预期投入:

{
    "Composite": [{
            "FacComp": {
                "geometry": {
                    "coordinates": [121.63646666666666, 29.10262638888889]
                },
                "Fac": {
                    "Category": "44500",
                    "DatetimeCreated": " 2018-11-29 10:48:43",
                    "FacSk": "-1",
                    "CoordBasis": "2"
                },
                "FacTie": [{
                        "DatetimeCreated": " 2018-11-29 10:48:43",
                        "FacTieSk": "-1",
                        "TieFromSk": "-1",
                        "TieToSk": "-1",
                        "TieToEntity": "FAC"
                    }
                ]
            }
        }, {
            "FacComp": {
                "geometry": {
                    "coordinates": [121.63646666666666, 29.10262638888889]
                },
                "Fac": {
                    "Category": "44500",
                    "DatetimeCreated": " 2018-11-29 10:48:43",
                    "FacSk": "-1",
                    "CoordBasis": "2"
                },
                "FacTie": [{
                        "DatetimeCreated": " 2018-11-29 10:48:43",
                        "FacTieSk": "-1",
                        "TieFromSk": "-1",
                        "TieToSk": "-1",
                        "TieToEntity": "FAC"
                    }
                ]
            }
        }
    ]
}

相反,我的输出低于输出(请参阅第二个元素中的FacTie,其中有2个而不是1个。

{
  "Composite" : [ {
    "FacComp" : {
      "geometry" : {
        "coordinates" : [ 121.63646666666666, 29.10262638888889 ]
      },
      "Fac" : {
        "Category" : "44500",
        "DatetimeCreated" : " 2018-11-29 10:48:43",
        "FacSk" : "-1",
        "CoordBasis" : "2"
      },
      "FacTie" : [ {
        "DatetimeCreated" : " 2018-11-29 10:48:43",
        "FacTieSk" : "-1",
        "TieFromSk" : "-1",
        "TieToSk" : "-1",
        "TieToEntity" : "FAC"
      } ]
    }
  }, {
    "FacComp" : {
      "geometry" : {
        "coordinates" : [ 121.63646666666666, 29.10262638888889 ]
      },
      "Fac" : {
        "Category" : "44500",
        "DatetimeCreated" : " 2018-11-29 10:48:43",
        "FacSk" : "-1",
        "CoordBasis" : "2"
      },
      "FacTie" : [ {
        "FacTieSk" : "-1",
        "TieFromSk" : "-1",
        "TieToSk" : "-1",
        "TieToEntity" : "FAC"
      }, {
        "DatetimeCreated" : " 2018-11-29 10:48:43",
        "FacTieSk" : "-1",
        "TieFromSk" : "-1",
        "TieToSk" : "-1",
        "TieToEntity" : "FAC"
      } ]
    }
  } ]
}

1 个答案:

答案 0 :(得分:0)

第二部分FacComp中有一个空值(在查看第一个规范后的输出时),因此在您的两个规范之间添加以下代码以删除空值:

  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=recursivelySquashNulls"
    }
  },