Need help with parsing XML to JSON
Hi, This is the first time I am connecting with AspDotNetStoreFron portal using WSI. They send the xml in the following format and I cannot use the Celigo XML to JSON parser as it says format not correct. Talked with Celigo support person also and they said it needs to be clean and below are his suggestions
1. < and & need to be decoded properly.
2. "False" or "True" and need to be lowercase "false" or "true" to work correctly
3. All fields need to be properly enclosed to allow for parsing to JSON without any missing fields
So looks like with this format I cannot convert to JSON with the Celigo's built in parser. I tried to do a Javascript code to clean up and convert. I was able to do the clean up but for converting libraries needs to be imported which I can't do in Celigo. Any help would be greatly appreciated to convert this xml to jSON
"<?xml version=\"1.0\" encoding=\"utf-8\"?><AspDotNetStorefrontImportResult Version=\"7.1\" DateTime=\"8/20/2024 10:18:34 PM\"><GetProduct ID=\"11735\" GUID=\"\"><Product Action=\"Update\" ID=\"11735\" Name=\"OFF-SITE WORK KIT\" SKU=\"MPC1908\" GUID=\"1d920cfc-fcd8-45b0-b025-dc3e774a99f7\"><Name>OFF-SITE WORK KIT</Name><Summary></Summary><Description>Set Includes #2953 Wireless Charging Mouse Pad With Phone Stand, #1343 Jotter With Sticky Notes And Flags, #1333 - 3-Tier Stationary Set, #2496 3-In-1 Xoopar Octo-Charging Cables, #224 .5 Oz. Screen Cleaner And Spray\n<br />\n<br />\n<br />\n&nbsp;As low as 35.49 each @450 qty.<br /></Description><MiscText></MiscText><Notes></Notes><FroogleDescription></FroogleDescription><SKU>MPC1908</SKU><ManufacturerPartNumber></ManufacturerPartNumber><SE><SEName>off-site-work-kit</SEName><SETitle></SETitle><SEKeywords></SEKeywords><SEDescription></SEDescription><SEAltText></SEAltText></SE><SizeOptionPrompt></SizeOptionPrompt><ColorOptionPrompt></ColorOptionPrompt><ProductType Name=\"Generic Product\" ID=\"1\" GUID=\"b60e6a65-ec2a-4fca-8f16-029bb03729cc\" /><TaxClass Name=\"Goods\" ID=\"1\" GUID=\"ff20a290-6af2-4bf9-a550-217e4b7e342b\" /><SalesPrompt Name=\"On Sale For\" ID=\"1\" GUID=\"511a94c2-a260-4a0a-bd21-42f257da5563\" /><Display><XmlPackage>product.simpleproduct.xml.config</XmlPackage><ColWidth>4</ColWidth><SkinID>0</SkinID><TemplateName></TemplateName></Display><Images><ImageFilenameOverride></ImageFilenameOverride></Images><RelatedProducts></RelatedProducts><UpsellProducts DiscountPercentage=\"0.0000\"></UpsellProducts><RequiresProducts></RequiresProducts><InventoryType><TrackInventoryBySizeAndColor>False</TrackInventoryBySizeAndColor><WarehouseLocation></WarehouseLocation></InventoryType><IsAKit>False</IsAKit><IsSystem>False</IsSystem><ShowBuyButton>False</ShowBuyButton><Published>True</Published><Wholesale>False</Wholesale><RequiresRegistration>False</RequiresRegistration><HidePriceUntilCart>False</HidePriceUntilCart><IsCallToOrder>True</IsCallToOrder><ExcludeFromPriceFeeds>False</ExcludeFromPriceFeeds><RequiresTextOption>False</RequiresTextOption><TextOptionMaxLength>0</TextOptionMaxLength><TextOptionPrompt></TextOptionPrompt><StoreMappings AutoCleanup=\"true\"><Store StoreId=\"1\" /></StoreMappings><Mappings AutoCleanup=\"true\"><Entity EntityType=\"Category\" Name=\"MPC Essentials\" XPath=\"/MPC Essentials\" ID=\"520\" GUID=\"289d47c8-21de-402d-9fe8-8accd58e9976\" DisplayOrder=\"1\" /><Entity EntityType=\"Category\" Name=\"Work from Home\" XPath=\"/MPC Essentials/Work from Home\" ID=\"522\" GUID=\"6f1ceea0-5972-4e68-9174-d6319aea954f\" DisplayOrder=\"1\" /><Entity EntityType=\"Manufacturer\" Name=\"MPC Promotions\" XPath=\"/\" ID=\"1\" GUID=\"3a351ca9-92b2-4c26-8666-d14886321918\" DisplayOrder=\"1\" /></Mappings><ExtensionData></ExtensionData><ExtensionData2></ExtensionData2><ExtensionData3></ExtensionData3><ExtensionData4></ExtensionData4><ExtensionData5></ExtensionData5><Variants AutoCleanup=\"true\"><Variant <Name></Name><Description><span>\n<h2></h2>\n</span></Description><SE><SEName></SEName><SEKeywords></SEKeywords><SEDescription></SEDescription></SE><FroogleDescription></FroogleDescription><ProductID>11735</ProductID><SKUSuffix></SKUSuffix><ManufacturerPartNumber></ManufacturerPartNumber><GTIN></GTIN><Price>35.4900</Price><SalePrice>0</SalePrice><Weight>0.5000</Weight><MSRP>0</MSRP><Cost>0</Cost><Points>0</Points><Dimensions></Dimensions><Inventory>9999</Inventory><DisplayOrder>1</DisplayOrder><Notes></Notes><IsTaxable>True</IsTaxable><IsShipSeparately>False</IsShipSeparately><IsDownload>False</IsDownload><DownloadLocation></DownloadLocation><FreeShipping>0</FreeShipping><Published>True</Published><Wholesale>False</Wholesale><IsRecurring>False</IsRecurring><RecurringInterval>1</RecurringInterval><RecurringIntervalType>-1</RecurringIntervalType><RestrictedQuantities></RestrictedQuantities><MinimumQuantity>0</MinimumQuantity><Images><ImageFilenameOverride></ImageFilenameOverride></Images><CustomerEntersPrice>False</CustomerEntersPrice><CustomerEntersPricePrompt></CustomerEntersPricePrompt><ExtensionData></ExtensionData><ExtensionData2></ExtensionData2><ExtensionData3></ExtensionData3><ExtensionData4></ExtensionData4><ExtensionData5></ExtensionData5><Sizes></Sizes><Colors></Colors></Variant></Variants></Product></GetProduct></AspDotNetStorefrontImportResult>"
Comments
This looks like how xml looks when placed inside of a json/js variable. (everything is escaped)
AspDotNetStoreFront API should respond with regular xml, can you post a screenshot of your export?
Here is what I get(Cannot upload file for some reason). Here is part of the data
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><DoItUsernamePwdResponse xmlns="http://www.aspdotnetstorefront.com/"><DoItUsernamePwdResult><?xml version="1.0" encoding="utf-8"?><AspDotNetStorefrontImportResult Version="7.1" DateTime="8/23/2024 12:29:39 PM"><GetProduct ID="11735" GUID=""><Product Action="Update" ID="11735" Name="OFF-SITE WORK KIT" SKU="MPC1908" GUID="1d920cfc-fcd8-45b0-b025-dc3e774a99f7"><Name>OFF-SITE WORK KIT</Name><Summary></Summary><Description>Set Includes #2953 Wireless Charging Mouse Pad With Phone Stand, #1343 Jotter With Sticky Notes And Flags, #1333 - 3-Tier Stationary Set, #2496 3-In-1 Xoopar Octo-Charging Cables, #224 .5 Oz. Screen Cleaner And Spray
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;As low as 35.49 each @450 qty.&lt;br /&gt;
Bindu Joseph this is a pretty ugly response from an api. I would suggest you don't accept it as XML and instead accept as "Plain text" so that we don't put it through any parser. From there you have a couple options.
Thank you Tyler. So you are suggesting to create a parser in the script so that I don't need to use any library?
Bindu Joseph yeah something like this. I just used AI for this and didn't change much, but it highlights what you could do. You could also have a more simple script that just runs the replace statements, where that gives you valid XML, then you send that valid XML to another flow.
Input:
Output:
Script:
Bindu Joseph the XML itself is also invalid. I see it's missing an ending character for the Variant tag. So overall you'll need a script to clean this up, then send through a parser or do like above.
This is awesome!. Thank you so much Tyler for this. Really appreciate it
Please sign in to leave a comment.