Parsing Through Hybrid API Responses Using KingswaySoft

24 April 2024
KingswaySoft Team

Usually, API endpoints exposed are either based on SOAP (XML) or REST (JSON) service calls. These are straightforward to handle when it comes to either read or write to the endpoints. You could use our respective JSON, XML, or Web Service (when working with a WSDL-based service) components, to create a data flow based on your requirements. However, there are cases where the responses might be in a hybrid format - That is, for instance, an XML code snippet within a root JSON structure. In such situations, you need a proper strategy for working with the embedded XML snippet. In this blog post, we will show you how this can be achieved effectively. For this, we will use the following components, all of which are part of our SSIS Productivity Pack.

For demonstration purposes, we are using a dummy endpoint, which already has such a response available for us to try and handle using our components. You can click this link to open and view it in your browser.

Setting up the JSON Source component

To get started, we first need to create an HTTP connection manager that connects to the the URL that we just mentioned above (Please note that the URL may have an error when opening in some browsers, such as Firefox, but this should be considered as a false positive). Later in this blog post, we will discuss how to extract data from the service endpoint. As you can see, the document has a root JSON, with XML within it.

{
"XmlDoc": "<?xml version=\"1.0\"?>\n
<DocumentRoot>\n 
	<data>\n  
		<Employee_Number>12</Employee_Number>\n  
		<Person_Number>123</Person_Number>\n  
		<ESS_Authority_Level>6</ESS_Authority_Level>\n  
		<Position_Number>12</Position_Number>\n  
		<Position_Title>Team Lead</Position_Title>\n  
		<Authority_Level>2</Authority_Level>\n  
		<Attendance_Type_Code>FULL</Attendance_Type_Code>\n  
		<Employee_Status>ACTIVE</Employee_Status>\n  
		<Preferred_Name>John</Preferred_Name>\n  
		<Surname>Smith</Surname>\n  
	</data>\n\n
	<data>\n  
		<Employee_Number>25</Employee_Number>\n  
		<Person_Number>856</Person_Number>\n  
		<ESS_Authority_Level>6</ESS_Authority_Level>\n  
		<Position_Number>1438</Position_Number>\n  
		<Position_Title>Team Manager Information System</Position_Title>\n  
		<Authority_Level>1</Authority_Level>\n  
		<Attendance_Type_Code>FULL</Attendance_Type_Code>\n  
		<Employee_Status>ACTIVE</Employee_Status>\n  
		<Preferred_Name>Jane</Preferred_Name>\n  
		<Surname>Austin</Surname>\n  
	</data>
</DocumentRoot>",
"status": 1
}

Therefore, right after we have set up the HTTP connection manager, we need to use the JSON Source component, to read the JSON document. To achieve so, we head to the Document Designer Page of the JSON Source component and import the design from "web", as shown below.

JSON Source import.png

Once done, you should see that the root object has the "XmlDoc" and "status" parsed out as column values. As we have seen in the JSON document structure above, the "XmlDoc" node would contain the XML document within it. It is important to note that we have set this column to use DT_NTEXT data type so that it can accommodate and process large XML documents, which could happen in a real-life situation.

JSON Doucment.png

Now that we have the raw XML document in the SSIS pipeline buffer, we are ready to further extract data from it for the purposes of consuming data in the XML code snippet. To achieve so, we need to set up the transformation part, where the XML will be parsed.

XML transformations

To extract the values from within an XML structure in an SSIS column, we can use the XML Extract component. Here, we would first need to import a design by saving the XML structure in a notepad as an XML file and then import it as shown below. Note that when we save the file, we would unescape the text string.

XMLExtract Import.png

Once done, we need to make sure that we choose the input field in the Additional Settings page.

XMLExtract Additional Settings.png

The overall data flow should look as shown below.

Overall Data Flow.png

When we execute the data flow, you can notice that the XmlDoc column has the XML document (which will display as <Long Text> due to the XML datatype), and once passed through the XML Extract component, it will parse out through each node in the XML structure. This will also have the "status" from the JSON source prefixed as "_upstream." in the columns.

Final Output.png

Please note that the Dummy Destination Component is just to showcase the data using data viewers. In a real business case, this would be replaced by your actual service destination component.

Conclusion

KingswaySoft components can be easily configured and used to handle complex scenarios within your SSIS data flow, without occurring parsing errors. This is not only useful while dealing with web service responses, but can also be used for parsing such documents from files, or even from column values, depending on how your integration receives such values.

We hope this has helped!

Archive

November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags