Chapter 6

📖 JSON and XML

Structured data is organized according to defined fields and rules so software can store, search, and process it. In healthcare, examples include vital signs, diagnoses, medications, laboratory results, and allergies. A structure makes consistent exchange easier, but it does not guarantee that the entered data is complete or correct.

The main building blocks in HL7® FHIR®1 are called resources. A resource can be represented in formats such as JSON or XML.

JSON and XML are widely used beyond healthcare. FHIR uses familiar formats so systems can represent the same resource content in more than one machine-readable form.

JSON uses key-value pairs to represent data, which means it pairs a name (the key) with a piece of information (the value).

XML uses tags (special words enclosed in angle brackets, like <ingredient> or <step>) to label and describe different pieces of information.

A Patient resource in JSON and XML2

Example for patient resource instance.[^patientexample]
Choose Format:
FieldDetails
Activetrue
Deceasedfalse
Alt Names- Peter James Chalmers (OFFICIAL)
- Peter James Windsor (MAIDEN)
Contact Details-unknown- (HOME)
ph: (03) 5555 6473 (WORK)
ph: (03) 3410 5613 (MOBILE)
ph: (03) 5555 8834 (OLD)
534 Erewhon St, PeasantVille, Rainbow, Vic 3999 (HOME)
Next-of-KinBénédicte du Marché (female)
534 Erewhon St, PleasantVille Vic 3999 (HOME)
+33 (237) 998327
Valid Period2012 –> (ongoing)
LinksManaging Organization: Organization/1 “Gastroenterology”
{
"resourceType" : "Patient",
"id" : "example",
"text" : {
  "status" : "generated",
  "identifier" : [{
    "use" : "usual",
    "type" : {
      "coding" : [{
        "system" : "http://terminology.hl7.org/CodeSystem/v2-0203",
        "code" : "MR"
      }]
    },
  "system" : "urn:oid:1.2.36.146.595.217.0.1",
  "value" : "12345",
  "period" : {
    "start" : "2001-05-06"
    },
  "assigner" : {
    "display" : "Acme Healthcare"
  }
  }],
"active" : true,
"name" : [{
  "use" : "official",
  "family" : "Chalmers",
  "given" : ["Peter","James"]
  },
  {
    "use" : "usual",
    "given" : ["Jim"]
  },
  {
    "use" : "maiden",
    "family" : "Windsor",
    "given" : ["Peter",
    "James"],
    "period" : {
      "end" : "2002"
  }
}],
"telecom" : [{
"use" : "home"
},
{
"system" : "phone",
"value" : "(03) 5555 6473",
"use" : "work",
"rank" : 1
},
{
"system" : "phone",
"value" : "(03) 3410 5613",
"use" : "mobile",
"rank" : 2
},
{
"system" : "phone",
"value" : "(03) 5555 8834",
"use" : "old",
"period" : {
"end" : "2014"
}
}],
"gender" : "male",
"birthDate" : "1974-12-25",
"\_birthDate" : {
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
"valueDateTime" : "1974-12-25T14:35:45-05:00"
}]
},
"deceasedBoolean" : false,
"address" : [{
"use" : "home",
"type" : "both",
"text" : "534 Erewhon St PeasantVille, Rainbow, Vic 3999",
"line" : ["534 Erewhon St"],
"city" : "PleasantVille",
"district" : "Rainbow",
"state" : "Vic",
"postalCode" : "3999",
"period" : {
"start" : "1974-12-25"
}
}],
"contact" : [{
"relationship" : [{
"coding" : [{
"system" : "http://terminology.hl7.org/CodeSystem/v2-0131",
"code" : "N"
}]
}],
"name" : {
"family" : "du Marché",
"\_family" : {
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/humanname-own-prefix",
"valueString" : "VV"
}]
},
"given" : ["Bénédicte"]
},
"telecom" : [{
"system" : "phone",
"value" : "+33 (237) 998327"
}],
"address" : {
"use" : "home",
"type" : "both",
"line" : ["534 Erewhon St"],
"city" : "PleasantVille",
"district" : "Rainbow",
"state" : "Vic",
"postalCode" : "3999",
"period" : {
"start" : "1974-12-25"
}
},
"gender" : "female",
"period" : {
"start" : "2012"
}
}],
"managingOrganization" : {
"reference" : "Organization/1"
}
}
<?xml version="1.0" encoding="UTF-8"?>

<Patient xmlns="http://hl7.org/fhir">
  <id value="example"/>
      <!--     MRN assigned by ACME healthcare on 6-May 2001     -->
<identifier>
    <use value="usual"/>
    <type>
      <coding>
        <system value="http://terminology.hl7.org/CodeSystem/v2-0203"/>
        <code value="MR"/>
      </coding>
    </type>
    <system value="urn:oid:1.2.36.146.595.217.0.1"/>
    <value value="12345"/>
    <period>
      <start value="2001-05-06"/>
    </period>
    <assigner>
      <display value="Acme Healthcare"/>
    </assigner>
  </identifier>
  <active value="true"/>
      <!--     Peter James Chalmers, but called "Jim"     -->
  <name>
    <use value="official"/>
    <family value="Chalmers"/>
    <given value="Peter"/>
    <given value="James"/>
  </name>
  <name>
    <use value="usual"/>
    <given value="Jim"/>
  </name>
  <name>
        <!--    Maiden names apply for anyone whose name changes as a result of marriage - irrespective
     of gender    -->
    <use value="maiden"/>
    <family value="Windsor"/>
    <given value="Peter"/>
    <given value="James"/>
    <period>
      <end value="2002"/>
    </period>
  </name>
  <telecom>
    <use value="home"/>
        <!--     home communication details aren't known     -->
  </telecom>
  <telecom>
    <system value="phone"/>
    <value value="(03) 5555 6473"/>
    <use value="work"/>
    <rank value="1"/>
  </telecom>
  <telecom>
    <system value="phone"/>
    <value value="(03) 3410 5613"/>
    <use value="mobile"/>
    <rank value="2"/>
  </telecom>
  <telecom>
    <system value="phone"/>
    <value value="(03) 5555 8834"/>
    <use value="old"/>
    <period>
      <end value="2014"/>
    </period>
  </telecom>
      <!--     use FHIR code system for male / female     -->
  <gender value="male"/>
  <birthDate value="1974-12-25">
    <extension url="http://hl7.org/fhir/StructureDefinition/patient-birthTime">
      <valueDateTime value="1974-12-25T14:35:45-05:00"/>
    </extension>
  </birthDate>
  <deceasedBoolean value="false"/>
  <address>
    <use value="home"/>
    <type value="both"/>
    <text value="534 Erewhon St PeasantVille, Rainbow, Vic  3999"/>
    <line value="534 Erewhon St"/>
    <city value="PleasantVille"/>
    <district value="Rainbow"/>
    <state value="Vic"/>
    <postalCode value="3999"/>
    <period>
      <start value="1974-12-25"/>
    </period>
  </address>
  <contact>
    <relationship>
      <coding>
        <system value="http://terminology.hl7.org/CodeSystem/v2-0131"/>
        <code value="N"/>
      </coding>
    </relationship>
    <name>
      <family value="du Marché">
            <!--     the "du" part is a family name prefix (VV in iso 21090)     -->
        <extension url="http://hl7.org/fhir/StructureDefinition/humanname-own-prefix">
          <valueString value="VV"/>
        </extension>
      </family>
      <given value="Bénédicte"/>
    </name>
    <telecom>
      <system value="phone"/>
      <value value="+33 (237) 998327"/>
    </telecom>
    <address>
      <use value="home"/>
      <type value="both"/>
      <line value="534 Erewhon St"/>
      <city value="PleasantVille"/>
      <district value="Rainbow"/>
      <state value="Vic"/>
      <postalCode value="3999"/>
      <period>
        <start value="1974-12-25"/>
      </period>
    </address>
    <gender value="female"/>
    <period>
          <!--     The contact relationship started in 2012     -->
      <start value="2012"/>
    </period>
  </contact>
  <managingOrganization>
    <reference value="Organization/1"/>
  </managingOrganization>
</Patient>
RDF Turtle

FHIR also defines an RDF representation using Turtle. This beginner course focuses on the more commonly encountered JSON and XML formats.


  1. HL7, FHIR and the FHIR [FLAME DESIGN] are the registered trademarks of Health Level Seven International and their use does not constitute endorsement by HL7. ↩︎

  2. The examples show equivalent FHIR content represented in two different formats. ↩︎