简体   繁体   English

从mule esb中的JSON中提取所有特定字段

[英]Extract all particular field from JSON in mule esb

I have this json payload, I would want to collect all externalListingId in one shot - 我有这个json有效载荷,我想一次性收集所有externalListingId -

{
"listings": {
    "numFound": 3,
    "listing": [
        {
            "status": "INACTIVE",
            "pricePerTicket": {
                "amount": 100,
                "currency": "USD",
            },
            "paymentType": "1",
            "externalListingId": "12208278",
            "city": "New York"
        },
        {   "status": "ACTIVE",
            "pricePerTicket": {
                "amount": 4444,
                "currency": "USD"
            },
            "paymentType": "1",
            "externalListingId": "CID1421798897102:151681733",
            "city": "Seattle"
        }
      ]
   }
}

I am using MVEL expression - 我正在使用MVEL表达式 -

<enricher target="#[flowVars['sData']]" source="#[(externalListingId in payload.listing)]" doc:name="Message Enricher">
    <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
    </enricher>

But this is giving error !! 但这是错误的! - Message payload is of type: ReleasingInputStream. - 消息有效内容的类型为:ReleasingInputStream。

Scenario - I would like to collect all externalListingId into flowVariable, convert to hashmap. 场景 - 我想将所有externalListingId收集到flowVariable中,转换为hashmap。 I have another CSV file as input, would like to loop through that payload and check if this map contains the id!! 我有另一个CSV文件作为输入,想循环通过该有效负载,并检查此映射是否包含id !!

I am following this earlier post - Extracting array from JSON in mule esb 我正在关注这篇早期文章 - 在mule esb中从JSON中提取数组

You need to transform the message's streaming payload to an object with: 您需要将消息的流式有效负载转换为对象:

<json:json-to-object-transformer returnClass="java.lang.Object" />

before the enricher , and remove the one you have inside of it. enricher之前,移除它内部的那个。

You also need to fix your MEL, as the listings property is missing in it: 您还需要修复MEL,因为其中缺少listings属性:

source="#[(externalListingId in payload.listings.listing)]"

Source: http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-JSONProcessing 来源: http//www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-JSONProcessing

it worked with the same definition. 它使用相同的定义。

<flow name="test-mule-json-extractFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/json" doc:name="HTTP"/> <enricher source="#[(externalListingId in payload.listings.listing)]" target="#[flowVars.ids]" doc:name="Message Enricher"> <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/> </enricher> <logger message=":::::::::::::::#[flowVars.ids]" level="INFO" doc:name="Logger"/> </flow>

Note: the json input you mentioned is not valid due to available of an extra comma. 注意:由于可用额外的逗号,您提到的json输入无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM