How to filter data in mule- anypoint studio

∥☆過路亽.° 提交于 2019-12-13 05:22:36

问题


I get this response from the magento-connctor get-product operation:

{"product_id":"33","sku":"TEST","set":"18","type":"bundle","categories":["2","4","5","16","17","222"],"website["1","3","5","16"],"created_at":null,"updated_at":null,"type_id":null,"name":"test","description":null,"short_description":"test description","weight":null,"status":null,"url_key":null,"url_path":null,"visibility":null,"category_ids":null,"website_ids":null,"has_options":null,"gift_message_available":null,"price":null,"special_price":null,"special_from_date":null,"special_to_date":null,"tax_class_id":null,"tier_price":null,"meta_title":null,"meta_keyword":null,"meta_description":null,"custom_design":null,"custom_layout_update":null,"options_container":null,"additional_attributes":[{"key":"highlights","value":"testing Highlights"},{"key":"test_details","value":null},{"key":"frequently_asked_questions","value":"test_faq"}],"enable_googlecheckout":null}

How can I filter by attribute and remove some of the data from the payload?


回答1:


You can use Dataweave (Transform Message component in Anypoint Studio), take a look to the documentation:

https://docs.mulesoft.com/mule-user-guide/v/3.7/using-dataweave-in-studio

A sample script with your data:

%dw 1.0
%output application/json
---
{
    product_id: payload.product_id,
    sku: payload.sku,
    set: payload.set,
    type: payload.type,
    categories: payload.categories map ((category , indexOfCategory) -> category),
    website: payload.website map ((website , indexOfWebsite) -> website),
    created_at: payload.created_at
}


来源:https://stackoverflow.com/questions/34549817/how-to-filter-data-in-mule-anypoint-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!