1.10.4.2 JSON によるリソース記法

logo fhir

Representing Resources in JSON 「JSON でのリソースの表現」1.10.4.2

Though the representation of FHIR resources is described in XML, FHIR also defines a JSON representation of the resources. The JSON format for the resources follows the standard XML format very closely to make interconversion easy, and so that XPath queries can easily be mapped to query the JSON structures. The formal mime type for this format is application/fhir+json.

FHIR のリソースの表現は XML で記述されていますが、FHIR ではリソースの JSON 表現も定義しています。相互変換を簡単にするため、リソースの JSON 表記は、標準の XML 表記を厳密に踏襲していて、XPath クエリーが簡単に JSON 構造のクエリーにマッピングできるようになっています。この表記の公式の MIME タイプは application/fhir+json です。

Clients are free to choose whether to implement in XML or JSON. Servers must support XML, and can choose to support JSON. Note that systems must declare which format(s) they support. Also, the reference implementations include bi-direction conversion functionality between the two formats.

クライアントの実装で XML と JSON のどちらを選ぶかは自由です。サーバーは XML をサポートしなければならず、JSON も合わせてサポートするかは選択できます。システムはどの表記をサポートするかを宣言しなければなりません。また参照実装は、この 2 つの表記の双方向変換機能を含んでいます。

The JSON representation is described relative to the XML representation:

JSON 表現は、XML 表現に対し

  • The names for the JSON object members are the same as the names of the elements and attributes in XML, including for elements that may repeat. Property names are case sensitive
    • JSON のオブジェクト・メンバーの名前は、繰り返し可のエレメントを含め XML のエレメントやアトリビュートの名前と同一です。プロパティの名前は大文字小文字の区別があります。
  • In the data types, the primitive type integer is represented using a native JSON int, while boolean is represented using JSON's "true" and "false" values. Other primitive types such as string, decimal, etc. are represented as a JSON string, using the same serialisation as the XML form (including instant, which is represented as plain text, not in one of the proposed JSON custom date formats)
    • データタイプの中では、プリミティブ・データタイプの integer は JSON 固有の int で表されますが、boolean は JSON の "true" と "false" 値で表されます。その他のプリミティブ・データタイプ、string、decimal などは、XML 形式と同じデータストリーム化を用いて JSON の string で表されます。(JSON で提案されているカスタム・データ形式でなく、plain text で表現される instant を含みます。)
  • Just as in XML, JSON property attributes never have empty values; omit a value if it is empty
    • XML と全く同じように、JSON のプロパティのアトリビュートも空の値をとることはありません。空の場合はデータ自体を省略します。

There are differences too:

いくつかの違いもあります:

  • There are no namespaces in the JSON representation
    • JSON 表現にはネームスペースはありません。
  • The order of properties of an object not significant in the JSON representation, though order within an array must be maintained
    • オブジェクトのプロパティの順番は JSON 表現では重要ではありませんが、array の順番は保持しなければなりません。
  • JSON does not have a notion of attributes versus elements, so attributes (xml:id, value) are treated as JSON object members (see below for more details)
    • JSON にはアトリビュートとエレメントの違いはありません。したがってアトリビュート(xml:id,value) は JSON オブジェクト・メンバーとして扱われます。(詳細については下記参照)
  • JSON has a notation for arrays, which are used to represent repeating elements. Note that this is the case, even if they do not repeat in the actual instance
    • JSON のは array の表現があり、繰り返しエレメントの表現に使われます。これは実際のインスタンスでエレメントが繰り返さない場合も適用されます。
  • The XHTML <div> element in the Narrative datatype is represented as a single escaped string of XHTML. This is to avoid problems in JSON with mixed content etc. The XHTML most still conform to the rules described above
    • Narrative データタイプ中の XHTML の <div> エレメントは、XHTML のエスケープされたひとつの文字列として表現されます。これは JSON のコンテンツ混合などによる問題を避けるためです。XHTML はそれでもほとんどの場合上記のルールに従います。

These differences - particularly the repeating element one, which cannot be avoided - mean that generic XML --> JSON converters are not able to perform correctly. The reference platforms provide XML <--> JSON conversion functionality that accommodates these FHIR-specific characteristics.

これらの違い、特に繰り返しエレメントに関するものは、避けることができないもので、XML から JSON への汎用ツールでの自動変換が正確にはできないことを意味します。参照実装プラットフォームでは、これらの FHIR 特有の特徴を踏まえた XML と JSON 相互変換機能を提供します。

JSON representation of primitive elements 「JSON 表記でのプリミティブ・エレメント」1.10.4.2.1

FHIR elements with primitive values are represented as a JSON object of the same name with a the value attribute of the element in a "value" property and (optionally) "_id" for the id attribute. JSON native types are used for boolean, integer and decimal, all other primitives are rendered as strings, and the whitespace is always significant (i.e. no leading and trailing spaces for non-strings). The JSON value "null" is never used.

プリミティブなデータ値を持った FHIR エレメントは、そのエレメントと同じ名前を持ったオブジェクトを用意し、そのエレメントの値は "value" という名のプロパティに入れ、省略可能な id アトリビュートが存在する場合は、"_id" という名のプロパティに入れることで表現されます。boolean、integer および decimal については、JSON のネイティブ・データタイプを用い、その他のプリミティブ・データタイプについては文字列で表現します。空白文字はつねに意味を持ちます(つまり、文字列でない部分にはその前後に空白はつきません)。JSON の値 "null" が使われることはありません。

<date value="1972-11-30"/> <deceased value="false" /> <count value="23" />

is represented in JSON as

は JSON では以下のように表現されます:

"date" : { value: "1972-11-30" } "deceased" : { value: false } "count" : { value: 23 }

All XML elements can have an 'id' attribute, which is represented in JSON as a property of name "_id":

すべての XML エレメントは 'id" アトリビュートを持つことができ、JSON では "_id" という名のプロパティで表現されます:

<dob id="314159" value="1972-11-30" />

is represented in JSON as:

は JSON では以下のように表現されます:

"dob": { "_id": "314159", "value": "1972-11-30" }

Repeating elements 「繰り返しエレメント」1.10.4.2.2

Repeating elements are rendered within a JSON array with the name of the element, so a repeating <dob> element in XML

繰り返しエレメントは、その名前の JSON の array で表現されるので、XML の繰り返しの <dob> エレメント

<dob value="2011-11-30" /> <dob id="314159" value="1972-11-30" />

is represented in JSON like so:

は JSON では次のように表現されます:

"dob": [ { "value": "2011-11-30" }, { "_id": "314159", "value": "1972-11-30" } ]

JSON representation of Resources, Elements, and Data types 「リソース、エレメントおよびデータタイプの JSON 表現」1.10.4.2.3

Resources, elements, and datatypes (types that contain named elements of other types) are represented using a JSON object, containing a member for each element in the datatype. Composites can have id attributes, which are converted to JSON members values, in the same manner as described for primitives. It comes before all other members. For example:

リソース、エレメントそしてデータタイプ(他のデータタイプの名前付きエレメントを中に含むタイプ)は、データタイプ中の各エレメントをメンバーとして含む JSON のオブジェクトを使って表現されます。コンポジットは id アトリビュートを持つことができ、プリミティブ・データタイプと同様に JSON メンバーの "_id" プロパティで表されます。その際 "_id" メンバーは他のメンバーに先行します。例えば:

<Person> <name> <use value="official" /> <given value="Karen" /> <family id="n1" value="Van" /> </name> <text> <status value="generated" /> <div xmlns="http://www.w3.org/1999/xhtml">...</div> </text> </Person>

is represented in JSON as:

は JSON では以下のように表現されます:

{ "Person" : { "name" : [{ "use" : { "value" : "official" }, "given" : [{ "value" : "Karen" }], "family" : [{ "_id" : "n1", "value" : "van" }] }], "text" : { "status" : { "value" : "generated" }, "div" : "<div xmlns='http://www.w3.org/1999/xhtml'>...</div>" } }

Things to note here are:

注意事項は以下の通りです:

  • Both given and family are repeating XML elements, so they are serialised as an Array whether or not they repeat in this instance
    • ファーストネームと、ファミリーネームはどちらも、繰り返しの XML エレメントで表現されていますので、このインスタンスでの繰り返しの有無にかかわらず、Array としてデータストリーム化されます。
  • Because the primitive element 'id' is in a resource, it is serialised as a JSON object
    • プリミティブ・データエレメント 'id' がリソースに含まれるので、JSON オブジェクトとしてデータストリーム化されます。
  • In the family part of 'name', the '_id' is added as the first member
    • 'name' の family の部分に、'_id' が最初のメンバーとして追加されます。
  • The XHTML content in the 'div' element which is in the Narrative element 'text' is represented as an escaped string in the value property in JSON. The xhtml's root element needs to be a <div> in the xhtml namespace
    • Narrative エレメント 'text' の中の 'div' エレメントの XHTML のコンテンツが、JSON の value プロパティの中でエスケープされた文字列として表現されています。XHTML のルート・エレメントは、XHTML のネームスペースの <div> である必要があります。

JSON Bundle Representation 「JSON のバンドル表現」1.10.4.2.4

In JSON bundles are represented using a JSON format that is tailored to the specific needs for bundles. Each element in the Xml feed definition has a JSON corresponding JSON object member with the same name. Here is an example feed returning search results for a person query:

JSON では、バンドルは、その特有の必要性を満たした特別な JSON 形式を用いて表現されます。XML フィード定義中の それぞれのエレメントは、対応する 同じ名前の JSON オブジェクトのメンバーを持ちます。人の検索結果として返される feed の例をここに示します:

{ "feed" : { "title" : "Search result", "updated" : "2012-09-20T12:04:45.6787909+00:00", "id" : "urn:uuid:50ea3e5e-b6a7-4f55-956c-caef491bbc08", "link" : [{ "rel" : "self", "href" : "http://ip-0a7a5abe:16287/fhir/person?format=json" }], "category" : [{ "term" : "[Tag Uri]", "label" : "[Tag Label]", "scheme" : "http://hl7.org/fhir/tag" }], "totalResults" : 12, "entry" : [{ "title" : "Resource of type Person, with id = 1 and version = 1", "link" : [{ "rel" : "self", "href" : "http://fhir.furore.com/fhir/person/@1/history/@1" }], "id" : "http://fhir.furore.com/fhir/person/@1", "updated" : "2012-05-29T23:45:32+00:00", "published" : "2012-09-20T12:04:47.3012429+00:00", "author" : [{ "name" : "Grahame Grieve / HL7 publishing committee" }], "category" : [{ "term" : "[Tag Uri]", "label" : "[Tag Label]", "scheme" : "http://hl7.org/fhir/tag" }], "content" : { "Person" : { ...person content in JSON... } }, "summary" : "<div xmlns=\"http://www.w3.org/1999/xhtml\">(text summary)</div>", }, ... other entries .... ] } }

Note that property names for elements that can repeat are not pluralized for consistency of overall approach. The mime type for a json bundle is also application/fhir+json.

繰り返し可能なエレメントのプロパティの名前は、一環した処理のために複数形にはされません。JSON バンドルの MIME タイプも application/fhir+json です。

Bundling versions - deletion「バージョンのバンドル − 削除」 1.10.4.2.4.1

When returning a set of versions for a resource, a version might indicate a deletion. While the XML format follows RFC 6721, the JSON format needs to use an entry item to retain the logical order of entries:

ひとつのリソースのバージョンの集合を返す時には、削除を示す必要があるときがあります。XML 形式では RFC 6721 に従いますが、JSON 形式では、エントリーの論理的順番を保持するために entry アイテムを使う必要があります。

.. feed .. "entry" : [ ... other entries ...., { "deleted" : "2012-05-29T23:45:32+00:00", "id" : "http://fhir.furore.com/fhir/person/@1", "link" : [{ "rel" : "self", "href" : "http://fhir.furore.com/fhir/person/@1/history/@1" }], }, ... other entries .... ] ... feed ...

The entry is known to be deleted because a date of deletion is given. An id must be provided, and a link may be provided.

削除日付があることで、この entry は削除されたことがわかります。id メンバーは必須で、link メンバーは追加可能です。

Binary Resources 「バイナリ・リソース」 1.10.4.2.4.2

There are situations where it is useful or required to handle pure binary content as resources. Typically, this is when the binary content is referred to from other FHIR Resources. The resource can contain any content, whether text, image, pdf, zip archive, etc. These resources are served in their native form on the rest interface, but can also be represented in XML or JSON, such as when including these resources in a bundle (used when it is convenient to include these in the feed directly rather than leaving them by reference).

場合によっては、リソースを純粋なバイナリとして取り扱うことが有用であったり、必要であったりすることがあります。よくあるのは、他の FHIR リソースからバイナリのコンテンツが参照された場合です。バイナリ・リソースは、テキスト、画像、PDF、ZIP アーカイブなど、どんなコンテンツをとることもできます。これらのリソースは REST インタフェースでは、元々の形で処理されますが、バンドルにこれらのリソースを含める場合のように XML や JSON で表現することもできます。(これはこれらのコンテンツを feed に直接含める方が、リファレンスのままにしておくより便利な時に使われます。)

In JSON, Binary resources are represented like this:

JSON ではバイナリ・リソースは以下のように表現されます:

"Binary" : { "contentType" : "[mime type]", "content" : "[base64 of data]" }

© HL7.org 2011 - 2013. FHIR v0.11-1712 generated on Fri, Sep 6, 2013 23:04+1000.

Warning: This version of FHIR is the DSTU ballot, and the stable version for the September/October connectathons. Implementers are welcome to experiment with the content defined here, but should note that the contents are subject to change without prior notice.

この日本語訳は、上記のバージョンの FHIR ドラフト仕様に基づいています。この内容に基づいてシステムを試作実装することは奨励されていますが、現在の仕様の性質上、事前の通知なしに内容の変更が行われることは、ご理解ください。