---
type: "doc"
source: "source/json.html"
---
\[%settitle JSON Format%\] \[%file newheader%\] \[%file newnavbar%\] <%fmtheader json%>
## JSON Representation of Resources
| Responsible Owner: [\[%wgt its%\]]([%wg its%]) Work Group | [Standards Status](versions#std-process):[Normative](versions#std-process) |
| --- | --- |
The JSON representation for a resource is based on the [JSON format described in STD 90 (RFC 8259)](https://www.rfc-editor.org/info/std90), and is described using this format:
{
"resourceType" : "[**\[Resource Type\]**](resourcelist "The resource type being referenced")",
"resourceDefinition" : "[(see below)](resource#additional "The resource definition for additional resources")",
// from [Source](json): [property0](json)
"[property1](json "long description")" : "<[\[primitive\]](datatypes)\>", // short description
"[property2](json "long description")" : { [\[Datatype\]](datatypes) }, // short description
"[property3](json "long description")" : { // Short Description
"[propertyA](json "long description")" : { [CodeableConcept](datatypes#CodeableConcept) }, // [Short Description](json) ([Example](terminologies#example))
},
"[property4](json "long description")" : \[{ // Short Description
"[propertyB](json "long description")" : { [Reference](references#Reference)([ResourceType](resourcelist)) } // **R!** Short Description
}\]
}
Using this format:
- To build a valid JSON instance of a resource, replace the contents of the property values with valid content as described by the type rules and content description found in the property value for each element
- In this example:
1. `property1` has a primitive datatype; the value of the property will be as described for the stated type
2. `property2` has a complex datatype; the value of the property is an object that has the content as described for the stated type
3. `property3` is an object property that contains additional properties (e.g., propertyA; the allowable properties are listed, and also include extensions as appropriate)
4. `property4` is an array property that contains items which are objects themselves. The items may have any of the types already encountered in points 1-3
5. `propertyA` is an example of an object property that has a binding to a value set - the Short description is a link to the value set. In addition, the binding strength is shown
6. `propertyB` is an example of an object property that has a reference to a particular kind of resource
- Property names are case-sensitive (though duplicates that differ only in case are never defined)
- Property names SHALL be unique. Note: this is not explicitly stated in the original JSON specification,so stated for clarity here
- Properties can appear in any order
- XHTML is represented as an escaped string
- Objects are never empty. If an element is present in the resource, it SHALL have properties as defined for its type, or 1 or more [extensions](extensibility)
- String property values can never be empty. Either the property is absent, or it is present with at least one character of content
- The **R!** denotes that an element is mandatory - it must be present (or in an array, at least one item must be present)
- In this format, `//` is used for comments. While // is legal in Javascript, it is not legal in JSON, and comments SHALL NOT be in JSON instances irrespective of whether particular applications ignore them
- The character encoding is always UTF-8
- The MIME-type for this format is `application/fhir+json`.
Given the way [extensions](extensibility) work, applications reading JSON resources will never encounter unknown properties. However, once an application starts trading with other applications that conform to later versions of this specification, unknown properties may be encountered. Applications MAY choose to ignore unknown properties in order to foster forwards compatibility in this regard, but may also choose not to.
### JSON representation of additional resources
When [additional resources](resource#additional) are represented in JSON, the resourceType property contains the name of the resource as allocated by HL7, and an additional property is present, `resourceDefinition`. The resourceDefinition value is a canonical reference to the definition of the resource and always includes the version explicitly, e.g.,
{
"resourceType" : "ViewDefinition",
"resourceDefinition" : "http://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition|2.0.0-pre",
"id": "a-valid-id",
// etc
}
The `resourceDefinition` property is a feature of the JSON format, and is not defined anywhere in the structural definitions of FHIR (in the same way that the `resourceType` property is not). The resourceDefinition property is not present if the resourceType is one defined in this specification.
### JSON Representation for repeating elements
Note that this page contains some XML examples for the purposes of comparison between the two formats. The formats page has a [comparison between the JSON and XML formats](resource-formats#comparison).
An element that has a maximum cardinality of >1 (e.g., `x..*` in the definitions) may occur more than once in the instance. In JSON, this is done by using an array type. Note that:
- The name of the array is singular
- An item that may repeat is represented as an array even in the case that it doesn't repeat so that the process of parsing the resource is the same either way
So a [CodeableConcept](datatypes#CodeableConcept) is represented in JSON like this:
{
"coding": \[
{
"system" : "http://snomed.info/sct",
"code" : "104934005"
},
{
"system" : "http://loinc.org",
"code" : "2947-0"
}
\]
}
XML for comparison:
...
\[%dragons-start%\]
NOTE: Elements may change whether they are allowed to repeat or not between versions, even once normative (see [cardinality rules for backward compatibility)](versions#f-compat-cardianality)).
Processors should be prepared to manage such changes.
\[%dragons-end%\] :
### JSON representation of primitive elements
FHIR elements with primitive datatypes are represented in two parts:
- A JSON property with the name of the element, which has a JSON type of number, boolean, or string
- a JSON property with `_` prepended to the name of the element, which, if present, contains the value's id and/or extensions
The FHIR types [integer](datatypes#integer), [unsignedInt](datatypes#unsignedInt), [positiveInt](datatypes#positiveInt) and [decimal](datatypes#decimal) are represented as a JSON number, the FHIR type [boolean](datatypes#boolean) as a JSON boolean, and all other types (including [integer64](datatypes#integer64)) are represented as a JSON string which has the same content as that specified for the relevant datatype. Whitespace is always significant (i.e., no leading and trailing spaces for non-strings).
"code" : "abc",
"birthDate" : "1972-11-30",
"deceased" : false,
"count" : 23
}
For comparison, this is represented in XML as
<**code** value="abc"/>
<**birthDate** value="1972-11-30"/>
<**deceased** value="false" />
<**count** value="23" />
\[%dragons-start%\]
When using a JavaScript JSON.parse() implementation, note that JavaScript natively supports only one numeric datatype, which is a floating point number. This can cause loss of precision for FHIR numbers. In particular, trailing 0s after a decimal point will be lost e.g., 2.00 will be converted to 2. The FHIR decimal datatype is defined such that precision, including trailing zeros, is preserved for presentation purposes, and this is widely regarded as critical for correct presentation of clinical measurements. Implementations should consider using a custom parser and big number library (e.g., [https://github.com/jtobey/javascript-bignum](https://github.com/jtobey/javascript-bignum)) to meet these requirements. See also [the precision extension]([%extensions-location%]StructureDefinition-quantity-precision).
\[%dragons-end%\]
If the value has an id attribute, or extensions, then this is represented as follows:
"birthDate": "1970-03-30",
"\_birthDate": {
"id": "314159",
"extension" : \[ {
"url" : "http://example.org/fhir/StructureDefinition/text",
"valueString" : "Easter 1970"
}\]
}
Note: If the primitive has an id attribute or extension, but no value, only the property with the `_` is rendered.
This is represented in XML as:
<**birthDate** id="314159" value="1970-03-30" >
...
...