![]() ![]() A design decision was made by the community that repeatable elements would be represented in the JSON as an array of objects, even if only a single instance occurs. XML messages carry no information about the repeatability of an element - in observing a single non-repeated element in an XML message, one can't know if it might be repeatable without referring to the schema. There are subtle differences in the specifications of JSON and XML that requires these conversions to be schema-aware. Using a generic XML to JSON converter on a LIXI2 XML message does not always produce a JSON message that will validate against the LIXI2 JSON Schema. ![]() Why can't I use a generic XML to JSON converter? The same XSLT can be executed in any programming language. To demonstrate the portability of XSLT transformations, we have also shown how to use the same XSLT instructions, but this time executed with JavaScript in the xml_to_json_xslt.js script. We demonstrate XSLT with Python in the xml_to_json_xslt.py script. Using XSLT to transform a LIXI2 message from XML to JSON is the most performant approach. Full instructions on setting up and using the LIXI PyPI Package are available here. The LIXI Python Package only requires a few lines of code and is perfect for executing conversion on the desktop (see the xml_to_json.py script). We use this project as part of our automated CI/CD testing framework before every new release by converting sample LIXI2 messages from XML to JSON using three different techniques and back to XML again.Įach technique results in identical messages after conversion, validated by executing the transformations on every sample in our samples repository (also available to LIXI members here) and confirming that resulting files are identical. We also explain some of the pitfalls that you need to watch out for when using a generic XML to JSON converter. We have published a project in LIXILab that demonstrates a number of methods for converting LIXI2 messages between XML and JSON showing how fast and easy these conversions are.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |