json - 如何在骡流中显示来自json的特定字段
问题描述
嗨,我正在尝试创建一个简单的 mule 流,在其中我从 rest url 获取 json 数据,
例如。{“令牌”:123,“id”:456,“电子邮件”:“abc@abc.com”,“状态”:“成功”}
现在我希望我的回复只显示 2 个字段,所以我的最终输出 json 将是这样的..
例如。{“id”:456,“电子邮件”:“abc@abc.com”}
我知道这是非常基本的。如果有人能帮助我,我会很高兴,因为我对骡子很基础。谢谢!
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="reqres.in" port="8080" doc:name="HTTP Request Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/api/users/2" method="GET" doc:name="HTTP"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
解决方案
由于您是 mule 新手,您可以使用简单的 set payload 和一些 json 路径表达式来尝试这个简单的解决方案。
<flow name="jsonTransform">
<http:listener config-ref="HTTP_Listener_Configuration" path="/jsonTransform" doc:name="HTTP" allowedMethods="POST"/>
<set-payload value="{ "id" : "#[json:id]", "email" : "#[json:email]" }" doc:name="Set Payload"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
推荐阅读
- java - 不同的构造函数(LOMBOK)
- apache-spark - Spark 内存使用量不断增加,而训练模型仍在继续
- linux - 多个文件的 Gnu/Linux (Bash) 批量命令
- laravel - jqgrid过滤工具栏删除的行
- php - PHP Post Empty 根据请求
- amp-html - 在行动 xhr 中传递 AMP 状态
- javascript - 来自 Grammarly Chrome 扩展的红色错误下划线位置不正确
- javascript - babel-loader 和 webpack 没有正确转换模板文字
- python - 为一个 app.route 使用来自不同 html 站点的 2 个输入?
- asp.net - 使用 RegularExpressionValidator 跨多行匹配特定表达式