Question
· Oct 23, 2020

How to convert XML to JSON from a %XML.TextReader? (Without a custom method)

Hi guys!!

Anyone of you, someday needed to convert a parsed XML (With %XML.TextReader), to a DynamicObject on caché? If anyone can help me, I'm grateful.

Discussion (2)0
Log in or sign up to continue

Hi Victor,

I assume that you need Dynamic Objects in order to create some JSON Output (so you can call %ToJSON() on the object to create a JSON string). So in my opinion, the complexity of your JSON object will drive these decisions - for example, how deeply nested will your JSON need to be?

From some familiarity with TextReader, it records every XML Element into a Property. So in theory, each Property can have its corresponding Dynamic Object which will be a Name/Value pair: Name = Name of Property; Value = Value of Property (i,e. XML Text Node)

It is hard to say more without seeing your XML structure or your JSON Spec. You may find the following links helpful:

https://community.intersystems.com/post/convert-xml-json

https://community.intersystems.com/post/size-limitation-tojson-large-stream

https://community.intersystems.com/post/how-could-we-include-json-object...