Wikidata/Development/Phase 2 JSON

This document is a draft, and should not be assumed to represent the ultimate structure.

This is a draft for how Phase 2 JSON could look like. You can copy and paste it into a JS engine to play around with it.

Specification

edit

The following draft describes how to serialize statements. We omit labels, descriptions, aliases and sitelinks as they are already implemented.

A property has a simple key-value pair "type" : type-id, e.g. "type" : "item", to designate its type.

Statements are given as a value to the "statements" key (like "sitelinks", "labels", etc.) on the top level of an entity. The value is an associative array with all statements.

The keys of the statement value are the property ids. The value is an associative array with all statements for a given property.

The keys of that value are the statement ids. The value is an associative array describing a statement. This looks as follows:

 { 
   "value" : serialization_of_value_as_an_object,
   serialization_of_qualifiers,
   "references" : {
     serialization_of_references
   },
   "rank" : rank-id
 }

Qualifiers are serialized as a key-value pair with the key being the property id of the qualifier and the value being an array of serialized values (an array because the same qualifier can be used several times).

The different snaks are represented through the value serialization. This allows for the qualifiers to be key-value pairs.

Value serialization

edit

The value serialization depends on the snak type and the data type. The snak type is given explicitly. If the snak type is "none" or "some", then no "value" key is present.

Datatype item

edit

The following serializes a value of type "item" with a PropertyValueSnak:

 { 
   "snaktype" : "value",
   "value" : "q123"
 }

The following serializes a value of type "item" with a PropertyNoValueSnak:

 { 
   "snaktype" : "none"
 }

The following serializes a value of type "item" with a PropertySomeValueSnak:

 { 
   "snaktype" : "some"
 }

PropertyIntervalSnak and PropertySomeIntervalSnak can not be used with datatype "item".

Datatype commons media

edit

The following serializes a value of type "Commons media" with a PropertyValueSnak.

 { 
   "snaktype" : "value",
   "value" : "File:Photo.jpg"
 }

All other snak types are not supported for the datatype commons media.

Other datatypes

edit

Will be defined as we go. Here are a few drafts.

Geo:

 { 
   "snaktype" : "value",
   "latitude" : 32.233,
   "longitude" : -2.233,
   "precision" : 0.001,
   "sphere" : "q123"
 }

Points in time:

 { 
   "snaktype" : "value",
   "value" : "1900-01-01T00:00:00",
   "precision" : "century"
 }

See also

edit