EvaluateJsonPathAttributeCustom - Nifi



我必须从使用InvokeHTTPCustom从api调用接收的json文件中提取属性。JSON文件包含以下示例数据:

[
{
"input_index": 0,
"candidate_index": 0,
"delivery_line_1": "1 Santa Claus Ln",
"last_line": "North Pole AK 99705-9901",
"delivery_point_barcode": "997059901010",
"components": {
"primary_number": "1",
"street_name": "Santa Claus",
"street_suffix": "Ln",
"city_name": "North Pole",
"state_abbreviation": "AK",
"zipcode": "99705",
"plus4_code": "9901",
"delivery_point": "01",
"delivery_point_check_digit": "0"
},
"metadata": {
"record_type": "S",
"zip_type": "Standard",
"county_fips": "02090",
"county_name": "Fairbanks North Star",
"carrier_route": "C004",
"congressional_district": "AL",
"rdi": "Commercial",
"elot_sequence": "0001",
"elot_sort": "A",
"latitude": 64.75233,
"longitude": -147.35297,
"coordinate_license": 1,
"precision": "Rooftop",
"time_zone": "Alaska",
"utc_offset": -9,
"dst": true
},
"analysis": {
"dpv_match_code": "Y",
"dpv_footnotes": "AABB",
"dpv_cmra": "N",
"dpv_vacant": "N",
"dpv_no_stat": "Y",
"active": "Y",
"footnotes": "L#"
}
},
{
"input_index": 1,
"candidate_index": 0,
"addressee": "Apple Inc",
"delivery_line_1": "1 Infinite Loop",
// truncated for brevity
}
]

我已经提取了所有必需的数据,如地址、州、城市、primary_number等。但是,当我尝试从元数据中提取纬度、经度时,它会导致evaluatejsonpathattributecustomm处理器失败。其他字符串格式的属性被正确提取。然而,这不是一个字符串,可能是问题,是我的诊断。我如何让它工作?我需要提取经度和纬度。请详细解释一下,因为我是新来的nifi。nifi中evaluatejsonpathattributecustomm的配置:

Attribute Name Input : x**.json
Attribute Name Output : latitude
JsonPathExpresssion : $[0].metadata.latitude
Splitif.. : False

这样做的一种方法是使用JOLT https://jolt-demo.appspot.com/。我建议使用JoltTransformJSON NiFi处理器,因为它真的可以帮助你轻松地提取你想要的数据。我已经尝试了您的具体要求,它将工作,以提取这些数据。你可以配置JOLT来提取你需要的任何数据,一旦你掌握了它的窍门,它可能会更容易。

[{
"operation": "shift",
"spec": {
"*": {
"metadata": {
"latitude": "latitude",
"longitude": "longitude"
}
}
}
}]