Hi all - I’ve created a new tool https://fhir-formats.github.io that’ll convert between the XML and JSON representations quickly - realtime, even. Comes in handy if you want to convert a resource without opening Postman up, and useful if you want to learn the wire formats just by editing the resources and watching them change.
You can use the little icon top-left to load some sample resources up.
Enjoy!
2 Likes
The converter has been updated and now works with FHIR 1.6.0.
Hi Vadim,
Very nice work. I have a question, though, concerning the Lua code. Can you explain a little about the process you used to create (and recreate) the Lua code that does the parsing/building of the XML or JSON?
Kevan Riley
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.
Hi Vadim,
is it possible that the conversion from XML to JSON has issues with the cardinality?
e.g. DocumentReference/category [0…*] is not transformed to an json-array when only one category is given in the xml.
the same problem occurs on the coding within the category.
and if i place two categories in the xml still only one is displayed in the JSON.
thanks for any feedback.
AndiY
this is awesome, great job man
thanks