如何在 wso2 esb 中连接两个 JSON 响应

How to concatenate two JSON responses in wso2 esb

我需要将两个 json 连接起来以将其转换为一个有效的 json 是:

   {

    "first": true,
    "second": {
        "name": "manoj",
        "age": "45"
    },
    "third": {
        "fourth": [{

                "class": "test12",
                "salary": "123456"
            },

            {
                "class": "test23",
                "salary": "15678"
            }
        ],
        "fifth": "hello"
    }
   }

 [{
        "item1": "123456",
        "item2": "5678"

    },
  {
        "item1": "8976",
        "item2": "abcd"

    }]

是否可以在不使用任何 jquery 的情况下将这两个连接起来。我需要一些与 wso2 esb 代码相关的东西。我尝试使用 enrich 和其他调解器,但到目前为止没有运气。

您可以使用 WSO2 ESB Payload Factory 调解器连接 json,如下所示,

<api xmlns="http://ws.apache.org/ns/synapse" name="ConcatAPI" context="/concat">
<resource methods="GET">
  <inSequence>
     <call>
        <endpoint>
           <http method="GET" uri-template="http://www.mocky.io/v2/56b2d88c13000057518945d4"/>
        </endpoint>
     </call>
     <enrich>
        <source type="body" clone="true"/>
        <target type="property" property="first-json"/>
     </enrich>
     <log level="custom">
        <property name="First json" expression="get-property('first-json')"/>
     </log>
     <call>
        <endpoint>
           <http method="GET" uri-template="http://www.mocky.io/v2/56b2d87d1300007c518945d3"/>
        </endpoint>
     </call>
     <payloadFactory media-type="xml">
        <format>
           <completeJson xmlns="">
              <firstjson></firstjson>
              <secondjson></secondjson>
           </completeJson>
        </format>
        <args>
           <arg evaluator="xml" expression="get-property('first-json')"/>
           <arg evaluator="xml" expression="$body"/>
        </args>
     </payloadFactory>
     <property name="messageType" value="application/json" scope="axis2"/>
     <send/>
  </inSequence>
  <outSequence/>
  <faultSequence/>
</resource>
</api>

请注意,我已从 mocky.io 网站的模拟服务中检索到您的 json。

谢谢。