Within FHIR there is a choice to be made on which formats you use to represent the resources “on the wire”. Currently with FHIR the choice is XML, JSON or both.
Recently when developing using FHIR I have had the need to “flip” between formats when creating documentation and implementation guides so I set about creating a simple widget to achieve this. One of the huge benefits that FHIR offers as opposed to the previous HL7 standards is the availability of a rich set of open source code to help with development, freely available so early in the standards development cycle.
Personally (as a C# developer/hacker/wannabe) I am naturally attracted to two key libraries
- The first is the C# reference library that is offered as part of the standard itself. This is generated automatically by the FHIR publication process and is clearly the starting point for FHIR developments in C# (This is linked of the front page of the FHIR site here)
- The second is Ewout Kramer’s FHIR API library on GitHub, this offers a rich set functionality for serialising and parsing FHIR objects ( and much, much, more )
So my objective was to build a command line tool that allowed either a single file or a directory of files to be flipped from “XML to JSON” or “JSON to XML”.
The tool I created is entitled “fhirjx”
fhirjx /from:(xml|json) /to:(xml|json) /source:(directory|filename) [/target:directory]
The tool can be used in automated build process (which is how I use it) on any .NET platform. Currently it only works on single resources so will need to give it a bit more attention so it works on bundles as well.