Hey, thanks for your interest!
The Lua code is handwritten to convert in two directions - xml to json and json to xml. Both conversions make use of a cut-down FHIR schema, XML to sort the elements in the right order and JSON to determine whenever the element needs to be of type object or array (and a few more little things).
For the JSON to XML conversion, JSON is loaded as native Lua tables, then those Lua tables are transformed into a table style that's accepted by the XML serialiser in order to spit out XML elements with attributes as desired.
For the XML to JSON conversion, XML is loaded as Lua tables, then it's simplified down to tables closely resembling plain Lua ones that convert to JSON well.
Hope that helps, let me know if you'd like to know anything else.