尝试使用JOLT

时间:2018-05-15 02:28:50

标签: json jolt

我正在尝试构建JSON对象的复杂嵌套数组。我正在努力使用JOLT获得我期望的结构。任何帮助将不胜感激。

我试图从appspot中理解JOLT,但我很难掌握递归迭代数据集。

  • " JobId"即使数组中有1000个对象,也应该是毫秒,这就是为什么我要生成" JobId"一次而不是在每个对象中尝试在下一次迭代中移动到正确的位置失败。

输入JSON是:

{
  "type": "FeatureCollection",
  "totalFeatures": 2,
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          13.429916995511855,
          52.54516530881942
        ]
      },
      "properties": {
        "feature_type": "BLDG",
        "feature_geometry": "point",
        "discipline": "LOC",
        "activity": "AC",
        "be_number": 12313,
        "category": 47400,
        "condition": "RDY",
        "review_date": "2018-03-28T21:36:32.325Z",
        "role_type": "INSG",
        "symbol_code": "-"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          16.429916995511855,
          91.54516530881942
        ]
      },
      "properties": {
        "feature_type": "Bridge",
        "feature_geometry": "point",
        "discipline": "LOC",
        "activity": "AC",
        "co_number": 12313,
        "category": 47400,
        "condition": "RDY",
        "review_date": "2018-03-28T21:36:32.325Z",
        "role_type": "KLDV",
        "symbol_code": "-"
      }
    }
    ]
}

到目前为止我提出的规范:

[{
    "operation": "shift",
    "spec": {
      "type": "type",
      "features": {
        "*": {
          "geometry": {
            "coordinates": {
              "0": "FacilityComposite[&3].Facility.Ilat",
              "1": "FacilityComposite[&3].Facility.Ilon"
            }
          },
          "properties": {
            "activity": "FacilityComposite[&2].Facility.Activity",
            "be_number": "FacilityComposite[&2].Facility.BeNumber",
            "category": "FacilityComposite[&2].Facility.Category",
            "condition": "FacilityComposite[&2].Facility.Condition",
            "role_type": ["FacilityComposite[&2].Facility.RoleType", "FacilityComposite[&2].FacForm.RoleType", "FacilityComposite[&2].FacTie[&2].RoleType"],
            "review_date": ["FacilityComposite[&2].Facility.ReviewDate", "FacilityComposite[&2].FacForm.ReviewDate", "FacilityComposite[&2].FacTie[&2].ReviewDate"]
          }
        }
      }
    }
    }, {
    "operation": "default",
    "spec": {
      "JobId": "${now():toNumber()}",
      "FacilityComposite[]": {
        "*": {
          "Facility": {
            "FacSk": "-1",
            "ClientId": "DISHNET",
            "ReviewDate": "${now()}"
          },
          "FacForm": {
            "FacSk": "-1",
            "ClientId": "DISHNET"
          },
          "FacTie": [{
            "FacTieSk": "-1",
            "TieFromSk": "-1",
            "TieToSk": "-1",
            "ClientId": "DISHNET"
          }]
        }
      }
    }
    }

]

规范的输出是:

{
  "type" : "FeatureCollection",
  "FacilityComposite" : [ {
    "Facility" : {
      "Ilat" : 13.429916995511855,
      "Ilon" : 52.54516530881942,
      "Activity" : "AC",
      "BeNumber" : 12313,
      "Category" : 47400,
      "Condition" : "RDY",
      "RoleType" : "INSG",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "ClientId" : "DISHNET",
      "FacSk" : "-1"
    },
    "FacForm" : {
      "RoleType" : "INSG",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "FacSk" : "-1",
      "ClientId" : "DISHNET"
    },
    "FacTie" : [ {
      "RoleType" : "INSG",
      "ReviewDate" : "2018-03-28T21:36:32.325Z"
    } ]
  }, {
    "Facility" : {
      "Ilat" : 16.429916995511856,
      "Ilon" : 91.54516530881942,
      "Activity" : "AC",
      "Category" : 47400,
      "Condition" : "RDY",
      "RoleType" : "KLDV",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "ClientId" : "DISHNET",
      "FacSk" : "-1"
    },
    "FacForm" : {
      "RoleType" : "KLDV",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "FacSk" : "-1",
      "ClientId" : "DISHNET"
    },
    "FacTie" : [ null, {
      "RoleType" : "KLDV",
      "ReviewDate" : "2018-03-28T21:36:32.325Z"
    } ]
  } ],
  "JobId" : "${now():toNumber()}"
}

预期输出为:

{
  "type" : "FeatureCollection",
  [ 
  "FacilityComposite" : {
    "Facility" : {
      "JobId" : "${now():toNumber()}"
      "Ilat" : 13.429916995511855,
      "Ilon" : 52.54516530881942,
      "Activity" : "AC",
      "BeNumber" : 12313,
      "Category" : 47400,
      "Condition" : "RDY",
      "RoleType" : "INSG",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "ClientId" : "DISHNET",
      "FacSk" : "-1"
    },
    "FacForm" : {
      "JobId" : "${now():toNumber()}"
      "RoleType" : "INSG",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "FacSk" : "-1",
      "ClientId" : "DISHNET"
    },
    "FacTie" : [ {
    "FacTieSk": "-1",
        "TieFromSk": "-1",
        "TieToSk": "-1",
        "JobId" : "${now():toNumber()}"
        "ClientId": "DISHNET"
        "RoleType" : "INSG",
        "ReviewDate" : "2018-03-28T21:36:32.325Z"
    } ]
  },  
  "FacilityComposite" :{    
    "Facility" : {
      "JobId" : "${now():toNumber()}"
      "Ilat" : 16.429916995511856,
      "Ilon" : 91.54516530881942,
      "Activity" : "AC",
      "Category" : 47400,
      "Condition" : "RDY",
      "RoleType" : "KLDV",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "ClientId" : "DISHNET",
      "FacSk" : "-1"
    },
    "FacForm" : {
      "JobId" : "${now():toNumber()}"
      "RoleType" : "KLDV",
      "ReviewDate" : "2018-03-28T21:36:32.325Z",
      "FacSk" : "-1",
      "ClientId" : "DISHNET"
    },
    "FacTie" : [ {
      "TieFromSk": "-1",
        "TieToSk": "-1",
        "JobId" : "${now():toNumber()}"
        "ClientId": "DISHNET"
        "RoleType" : "INSG",
        "ReviewDate" : "2018-03-28T21:36:32.325Z"
    } ]
  } ],

}

1 个答案:

答案 0 :(得分:0)

这是给我正在寻找的规格:

 [{
    "operation": "shift",
    "spec": {
      "type": "type",
      "features": {
        "*": {
          "geometry": {
            "coordinates": {
              "0": "FacilityComposite[&3].Facility.Ilat",
              "1": "FacilityComposite[&3].Facility.Ilon"
            }
          },
          "properties": {
            "activity": "FacilityComposite[&2].Facility.Activity",
            "be_number": "FacilityComposite[&2].Facility.BeNumber",
            "category": "FacilityComposite[&2].Facility.Category",
            "condition": "FacilityComposite[&2].Facility.Condition",
            "role_type": ["FacilityComposite[&2].Facility.RoleType", "FacilityComposite[&2].FacForm.RoleType", "FacilityComposite[&2].FacTie[&2].RoleType"],
            "review_date": ["FacilityComposite[&2].Facility.ReviewDate", "FacilityComposite[&2].FacForm.ReviewDate", "FacilityComposite[&2].FacTie[&2].ReviewDate"]
          }
        }
      }
    }
    }, {
    "operation": "default",
    "spec": {
      "JobId": "${now():toNumber()}",
      "FacilityComposite[]": {
        "*": {
          "Facility": {
            "FacSk": "-1",
            "ClientId": "DISHNET",
            "ReviewDate": "${now()}"
          },
          "FacForm": {
            "FacSk": "-1",
            "ClientId": "DISHNET"
          }
        }
      }
    }
    },
  {
    "operation": "modify-default-beta",
    "spec": {
      "FacilityComposite": {
        "*": {
          "FacTie": {
            "*": {
              "FacTieSk": "-1",
              "TieFromSk": "-1",
              "TieToSk": "-1",
              "ClientId": "DISHNET"
            }
          }
        }
      }
    }
    }
]