locked
Embed XML Message in JSON RRS feed

  • Question

  • Hi,

    I need to pass a JSON message to an API with an embedded XML in one of the node value. How can I achieve this?

    Required Output:

    {
        "ruleCode""TEST_XML",
        "inputParams": {
            "params": [
                {
                    "name""xmlString",
                    "value""<ns0:REQ_Root xmlns:ns0=\"http://BTSApps.Schema_REQ\">\r\n  <FirstName>Tom</FirstName>\r\n  <LastName>Hanks</LastName>\r\n  <City>Texas</City>\r\n</ns0:REQ_Root>"
                }
            ]
        }

    }

    but the SendPipeline with JSON Encoder converts the XML inside the node to JSON and results in the below format.

    {
        "ruleCode""TEST_XML",
        "inputParams": {
            "params": [
                {
                    "name""xmlString",
                    "value": {
                        "REQ_Root": {
                            "FirstName""Tom",
                            "LastName""Hanks",
                            "City""Texas"
                        }
                    }
                }
            ]
        }
    }

    Thanks

    Pavan


    Regards, Muppidi

    Monday, December 14, 2020 1:26 AM

Answers

  • Hi,

    I've resolved this issue by adding an extra map after the XML is embedded into the output message. I've used the same output schema as both input and output schemas in the extra map and mapped every field. This has solved the issue. 

    As I don't have much time to investigate further, I've followed this approach for now. Will try again later.

    Thanks.


    Regards, Muppidi

    • Marked as answer by Muppidi Sunday, December 20, 2020 11:44 PM
    Sunday, December 20, 2020 11:44 PM

All replies

  • Can you show us what the XML payload looks like before the JSON Encoder?

    I suspect that this is one scenario that the JSON Encoder won't be able to do

    You will either need to inject the XML payload after the JSON Encoder with another pipeline component, or would have to write a custom JSON Encoder pipeline component. 

    Tuesday, December 15, 2020 1:35 AM
  • Hi,

    I've resolved this issue by adding an extra map after the XML is embedded into the output message. I've used the same output schema as both input and output schemas in the extra map and mapped every field. This has solved the issue. 

    As I don't have much time to investigate further, I've followed this approach for now. Will try again later.

    Thanks.


    Regards, Muppidi

    • Marked as answer by Muppidi Sunday, December 20, 2020 11:44 PM
    Sunday, December 20, 2020 11:44 PM