嵌套Json - 提取数据策略

时间:2014-06-16 06:52:41

标签: apigee medical

我无法使用"提取数据"更大的嵌套json结果的策略。我将如何在apigee"提取数据"政策?特别是,我在npi,姓氏,名字和商业地址字段中进行了交互。 感谢。

{
"meta": {
    "rowCount": 1
},
"result": [
    {
        "npi": 1671836487,
        "type": "individual",
        "last_name": "HUTTER",
        "first_name": "JOHN",
        "name_prefix": "MR.",
        "credential": "MD",
        "business_address": {
            "address_line": "1MAINSTREET",
            "city": "HARTFORD",
            "state": "CT",
            "zip": "06106",
            "country_code": "US",
            "phone": "8605551212",
            "fax": "8605551212"
        },
        "practice_address": {
            "address_line": "1MAINST",
            "city": "HARTFORD",
            "state": "CT",
            "zip": "06106",
            "country_code": "US",
            "phone": "8605551212",
            "fax": "8605551212"
        },
        "enumeration_date": "2013-04-03T00: 00: 00.000Z",
        "last_update_date": "2013-04-03T00: 00: 00.000Z",
        "gender": "male",
        "provider_details": [
            {
                "healthcare_taxonomy_code": "101Y00000X",
                "license_number": "002295",
                "taxonomy_switch": "yes"
            }
        ],
        "sole_proprietor": "no"
    }
]

}

2 个答案:

答案 0 :(得分:1)

确保将content-type标头设置为application / json,以便ExtractVariable策略中的JSONPath选项有效。

这是一个提取上述内容的示例政策(在我自己的系统中验证):

<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
  <DisplayName>Extract Variables 1</DisplayName>
  <FaultRules/>
  <Properties/>

  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <JSONPayload>
    <Variable name="result">
        <JSONPath>$.result</JSONPath>
    </Variable>      
    <Variable name="npi">
        <JSONPath>$.result[0].npi</JSONPath>
    </Variable>
    <Variable name="last_name">
        <JSONPath>$.result[0].last_name</JSONPath>
    </Variable>
    <Variable name="first_name">
        <JSONPath>$.result[0].first_name</JSONPath>
    </Variable>
  </JSONPayload>
  <Source clearPayload="false">request</Source>
  <VariablePrefix>json</VariablePrefix>
</ExtractVariables>

还有一个示例AssignMessage策略可帮助您进行故障排除。如果您将此添加到没有目标的代理,它将使用提取的值发回一个简单的响应:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
  <DisplayName>Assign Message 1</DisplayName>
  <FaultRules/>
  <Properties/>

  <Set>
    <Payload>
      npi={json.npi},
      last_name={json.last_name},
      first_name={json.first_name}
    </Payload>
  </Set>

  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

以上的示例回复:

      npi=1671836487,
      last_name=HUTTER,
      first_name=JOHN

参考:

http://apigee.com/docs/api-services/content/extract-message-content-using-extractvariables http://apigee.com/docs/api-services/content/generate-or-modify-messages-using-assignmessage

答案 1 :(得分:-1)

应该能够做到这一点(我没有测试过):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="get-ressults">
    <DisplayName>Get Results</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="npi">
            $.result[*].npi
        </Variable>
        <Variable name="first_name">
            $.result[*].first_name
        </Variable>
        <!-- etc. -->
    </JSONPayload>
    <Source>response</Source>
    <VariablePrefix>results</VariablePrefix>
</ExtractVariables>