subject Must Be a Reference Object, Not a String
Reference elements such as Observation.subject are JSON objects with a reference property. Supplying a bare string is invalid JSON structure for a FHIR Reference.
FHIR · Error
The error
subject must be a Reference object, not a plain stringWhy it happens
Flattening a reference to a string during serialization, or hand-writing JSON and forgetting the wrapping object with the reference key.
How to fix it
Wrap the value in an object: { "reference": "Patient/example" }. Optionally add a display. The string form Patient/example goes inside the reference property, not as the value of subject itself.
Example
The snippet below triggers the error:
{
"resourceType": "Observation",
"status": "final",
"subject": "Patient/example"
}The corrected version:
{
"resourceType": "Observation",
"status": "final",
"subject": { "reference": "Patient/example" }
}Frequently asked questions
What does a FHIR Reference look like?
A Reference is an object: { "reference": "Patient/123", "display": "John Doe" }. The relative or absolute pointer lives in the reference property. The whole thing is never a bare string.
Related
- Open the FHIR Validator
- All validation errors
- resourceType Is Required
- Unknown FHIR R4 Resource Type
- Required Element Is Missing for This Resource
- gender Must Be male, female, other, or unknown
- birthDate Must Be YYYY, YYYY-MM, or YYYY-MM-DD
- instant Must Include a Timezone
- Resource id Has an Invalid Format
- Reference Should Be Type/id, urn:uuid, or an Absolute URL