-1

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

[
    {
        "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 等。但是,当我尝试从元数据中提取纬度、经度时,它会导致 EvaluateJsonPathAttributeCustom 处理器失败。其他字符串格式的属性被正确提取。但是,这不是字符串,可能是问题,这是我的诊断。我如何让这个工作?我需要提取经度和纬度。请给出详细解释,因为我是 nifi 新手。EvaluateJsonPathAttributeCustom 在 nifi 中的配置:

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

1 回答 1

0

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

    [{
  "operation": "shift",
  "spec": {
    "*": {
      "metadata": {
        "latitude": "latitude",
        "longitude": "longitude"
      }
    }
  }
  }]
于 2021-09-03T12:13:04.050 回答