Help:JSON format

From semantic-mediawiki.org
(Redirected from Help:JSON format)
JSON format
Outputs semantic data in JSON format
Collection
Further Information
Provided by: Semantic MediaWiki
Added: 1.4.2
Compatibility change: Semantic MediaWiki 1.8.0
Removed: still supported
Requirements: none
Format name: json
Enabled? Indicates whether the result format is enabled by default upon installation of the respective extension. yes
Authors: mwjames , Jeroen De Dauw , Fabian Howahl
Categories: export · plaintext
Table of Contents

The result format json is used to produce links to JSON files. The export syntax has changed starting with Semantic MediaWiki 1.8.0Released on 2 December 2012 and compatible with MW 1.17.0 - 1.22.x
(except 1.22.1).
.

The change in the export syntax was necessary to ensure a higher validity among export formats, a reliance on available serialization methods, and elimination of specific error prone conversion procedures.

Parameters[edit]

General[edit]

Parameter Type Default Description
source text empty Alternative query source
limit whole number 100 The maximum number of results to return
offset whole number 0 The offset of the first result
link text all Show values as links
sort list of texts empty Property to sort the query by
order list of texts empty Order of the query sort
headers text show Display the headers/property names
mainlabel text no The label to give to the main page name
intro text empty The text to display before the query results, if there are any
outro text empty The text to display after the query results, if there are any
searchlabel text JSON Text for continuing the search
default text empty The text to display if there are no query results

Format specific[edit]

Parameter Type Default Description
type text full Serialization type
prettyprint yes/no empty A pretty-print output that displays additional indents and newlines
unescape yes/no empty Output to contain unescaped slashes and multibyte Unicode characters

Examples[edit]

Cities in Germany[edit]

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]] 
 |?Area
 |format=json
 |prettyprint=yes
 |searchlabel=JSON output
}}
Result as Table
 Has area
Berlin891.85 km²344.34 sqmi
Cologne
Frankfurt248.31 km²95.87 sqmi
Munich310.43 km²119.86 sqmi
Stuttgart207.36 km²80.06 sqmi
Würzburg
Result as json

JSON output

Export (as pretty print)[edit]

{
    "printrequests": [
        {
            "label": "",
            "typeid": "_wpg",
            "mode": 2
        },
        {
            "label": "Area",
            "typeid": "_qty",
            "mode": 1
        }
    ],
    "results": {
        "Berlin": {
            "printouts": {
                "Area": [
                    {
                        "value": 891.85,
                        "unit": "km\u00b2"
                    }
                ]
            },
            "fulltext": "Berlin",
            "fullurl": "http:\/\/localhost\/mw\/index.php\/Berlin",
            "namespace": 0,
            "exists": true
        }
    },
    "rows": 1
}

Query with different datatypes[edit]

Syntax
{{#ask: [[Has_annotation_uri::+]]
|?Has_annotation_uri=anu
|?Has_boolean=boo
|?Has_code=cod
|?Has_date=dat
|?Has email address=ema
|?Has Wikidata item ID=eid
|?Has coordinates=geo
|?Has number=num
|?Has mlt=mlt
|?Has example=wpg
|?Telephone number=tel
|?Has temperatureExample=tem
|?Area=qty
|?SomeProperty=txt
|?Has Wikidata Reference=ref_rec
|?Soccer result=rec
|?Has_URL=uri
|format=json
|limit=1
}}
Result as List
  1. List of datatypes (anu: https://www.semantic-mediawiki.org, boo: true, cod:
    Code
    is preserved but variables are expanded, e.g:
    Help:List of datatypes
    is displayed as the name of this page instead of FULLPAGENAME
    , dat: 22 May 2015 17:32:00, ema: president@whitehouse.gov, eid: Q9682, geo: 32° 42' 54", -117° 9' 45", num: 47,000.11, mltGeneric property for monolingual text: Monoglingual text in english (en), Texte monoglinguel en français (fr), Einsprachiger Text auf Deutsch (de), wpg: Semantic MediaWiki, telThis property is a special property in this wiki.: +1-800-225-5288, tem: 296.15 K23 °C
    73.4 °F
    533.07 °R
    , qty: 1,052.00 km²406.18 sqmi
    , txt: Did you create the page for Tokyo 東京 ? Yes ✓, rec: 22 March 2015 (Bayern München, Borussia Mönchengladbach, 0, 2), uri: http://www.whitehouse.gov)

... further results

Result as json

JSON

json source code
{
    "printrequests": [
        {
            "label": "",
            "key": "",
            "redi": "",
            "typeid": "_wpg",
            "mode": 2,
            "format": false
        },
        {
            "label": "anu",
            "key": "Has_annotation_uri",
            "redi": "",
            "typeid": "_anu",
            "mode": 1,
            "format": ""
        },
        {
            "label": "boo",
            "key": "Has_boolean",
            "redi": "",
            "typeid": "_boo",
            "mode": 1,
            "format": ""
        },
        {
            "label": "cod",
            "key": "Has_code",
            "redi": "",
            "typeid": "_cod",
            "mode": 1,
            "format": ""
        },
        {
            "label": "dat",
            "key": "Has_date",
            "redi": "",
            "typeid": "_dat",
            "mode": 1,
            "format": ""
        },
        {
            "label": "ema",
            "key": "Has_email_address",
            "redi": "",
            "typeid": "_ema",
            "mode": 1,
            "format": ""
        },
        {
            "label": "eid",
            "key": "Has_Wikidata_item_ID",
            "redi": "",
            "typeid": "_eid",
            "mode": 1,
            "format": ""
        },
        {
            "label": "geo",
            "key": "Has_coordinates",
            "redi": "",
            "typeid": "_geo",
            "mode": 1,
            "format": ""
        },
        {
            "label": "num",
            "key": "Has_number",
            "redi": "",
            "typeid": "_num",
            "mode": 1,
            "format": ""
        },
        {
            "label": "mlt",
            "key": "Has_mlt",
            "redi": "",
            "typeid": "_mlt_rec",
            "mode": 1,
            "format": ""
        },
        {
            "label": "wpg",
            "key": "Has_example",
            "redi": "",
            "typeid": "_wpg",
            "mode": 1,
            "format": ""
        },
        {
            "label": "tel",
            "key": "_tel",
            "redi": "",
            "typeid": "_tel",
            "mode": 1,
            "format": ""
        },
        {
            "label": "tem",
            "key": "Has_temperatureExample",
            "redi": "",
            "typeid": "_tem",
            "mode": 1,
            "format": ""
        },
        {
            "label": "qty",
            "key": "Area",
            "redi": "",
            "typeid": "_qty",
            "mode": 1,
            "format": ""
        },
        {
            "label": "txt",
            "key": "SomeProperty",
            "redi": "",
            "typeid": "_txt",
            "mode": 1,
            "format": ""
        },
        {
            "label": "ref_rec",
            "key": "Has_Wikidata_Reference",
            "redi": "",
            "typeid": "_ref_rec",
            "mode": 1,
            "format": ""
        },
        {
            "label": "rec",
            "key": "Soccer_result",
            "redi": "",
            "typeid": "_rec",
            "mode": 1,
            "format": ""
        },
        {
            "label": "uri",
            "key": "Has_URL",
            "redi": "",
            "typeid": "_uri",
            "mode": 1,
            "format": ""
        }
    ],
    "results": {
        "Help:List of datatypes": {
            "printouts": {
                "anu": [
                    "https:\/\/www.semantic-mediawiki.org"
                ],
                "boo": [
                    "t"
                ],
                "cod": [
                    "Code\nis preserved but variables are expanded, e.g:\nHelp:List of datatypes\nis displayed as the name of this page instead of FULLPAGENAME"
                ],
                "dat": [
                    {
                        "timestamp": "1432315920",
                        "raw": "1\/2015\/5\/22\/17\/32\/0\/0"
                    }
                ],
                "ema": [
                    "mailto:president@whitehouse.gov"
                ],
                "eid": [
                    "Q9682"
                ],
                "geo": [
                    {
                        "lat": 32.715,
                        "lon": -117.1625
                    }
                ],
                "num": [
                    47000.11
                ],
                "mlt": [
                    {
                        "Text": {
                            "label": "Text",
                            "key": "_TEXT",
                            "typeid": "_txt",
                            "item": [
                                "Monoglingual text in english"
                            ]
                        },
                        "Language code": {
                            "label": "Language code",
                            "key": "_LCODE",
                            "typeid": "__lcode",
                            "item": [
                                "en"
                            ]
                        }
                    },
                    {
                        "Text": {
                            "label": "Text",
                            "key": "_TEXT",
                            "typeid": "_txt",
                            "item": [
                                "Texte monoglinguel en fran\u00e7ais"
                            ]
                        },
                        "Language code": {
                            "label": "Language code",
                            "key": "_LCODE",
                            "typeid": "__lcode",
                            "item": [
                                "fr"
                            ]
                        }
                    },
                    {
                        "Text": {
                            "label": "Text",
                            "key": "_TEXT",
                            "typeid": "_txt",
                            "item": [
                                "Einsprachiger Text auf Deutsch"
                            ]
                        },
                        "Language code": {
                            "label": "Language code",
                            "key": "_LCODE",
                            "typeid": "__lcode",
                            "item": [
                                "de"
                            ]
                        }
                    }
                ],
                "wpg": [
                    {
                        "fulltext": "Semantic MediaWiki",
                        "fullurl": "https:\/\/www.semantic-mediawiki.org\/wiki\/Semantic_MediaWiki",
                        "namespace": 0,
                        "exists": "1",
                        "displaytitle": ""
                    }
                ],
                "tel": [
                    "tel:+1-800-225-5288"
                ],
                "tem": [
                    296.15
                ],
                "qty": [
                    {
                        "value": 1052,
                        "unit": "km\u00b2"
                    }
                ],
                "txt": [
                    "Did you create the page for Tokyo \u6771\u4eac ? Yes \u2713"
                ],
                "ref_rec": [
                    {
                        "Has URL": {
                            "label": "Has URL",
                            "key": "Has_URL",
                            "typeid": "_uri",
                            "item": [
                                "https:\/\/en.wikipedia.org\/wiki\/Data_type"
                            ]
                        },
                        "Has Wikidata item ID": {
                            "label": "Has Wikidata item ID",
                            "key": "Has_Wikidata_item_ID",
                            "typeid": "_eid",
                            "item": [
                                "Q190087"
                            ]
                        }
                    }
                ],
                "rec": [
                    {
                        "Soccer date": {
                            "label": "Soccer date",
                            "key": "Soccer_date",
                            "typeid": "_dat",
                            "item": [
                                {
                                    "timestamp": "1426982400",
                                    "raw": "1\/2015\/3\/22"
                                }
                            ]
                        },
                        "Soccer home team": {
                            "label": "Soccer home team",
                            "key": "Soccer_home_team",
                            "typeid": "_wpg",
                            "item": [
                                {
                                    "fulltext": "Bayern M\u00fcnchen",
                                    "fullurl": "https:\/\/www.semantic-mediawiki.org\/wiki\/Bayern_M%C3%BCnchen",
                                    "namespace": 0,
                                    "exists": "",
                                    "displaytitle": ""
                                }
                            ]
                        },
                        "Soccer guest team": {
                            "label": "Soccer guest team",
                            "key": "Soccer_guest_team",
                            "typeid": "_wpg",
                            "item": [
                                {
                                    "fulltext": "Borussia M\u00f6nchengladbach",
                                    "fullurl": "https:\/\/www.semantic-mediawiki.org\/wiki\/Borussia_M%C3%B6nchengladbach",
                                    "namespace": 0,
                                    "exists": "1",
                                    "displaytitle": ""
                                }
                            ]
                        },
                        "Soccer homescore": {
                            "label": "Soccer homescore",
                            "key": "Soccer_homescore",
                            "typeid": "_num",
                            "item": [
                                0
                            ]
                        },
                        "Soccer guestscore": {
                            "label": "Soccer guestscore",
                            "key": "Soccer_guestscore",
                            "typeid": "_num",
                            "item": [
                                2
                            ]
                        }
                    }
                ],
                "uri": [
                    "http:\/\/www.whitehouse.gov"
                ]
            },
            "fulltext": "Help:List of datatypes",
            "fullurl": "https:\/\/www.semantic-mediawiki.org\/wiki\/Help:List_of_datatypes",
            "namespace": 12,
            "exists": "1",
            "displaytitle": ""
        }
    },
    "serializer": "SMW\\Serializers\\QueryResultSerializer",
    "version": 2,
    "rows": 1
}

List of datatype IDs[edit]

IDDatatypeDescriptionin this wikiHelp pageProvided by
_anu
Annotation URIHolds URIs, but has some technical differences during export compared to the "URL" typeTypes/Annotation URIHelp:Datatype "Annotation URI"Semantic MediaWiki
_boo
BooleanHolds boolean (true/false) valuesTypes/BooleanHelp:Datatype "Boolean"Semantic MediaWiki
_cod
CodeHolds technical, pre-formatted texts (similar to datatype Text)Types/CodeHelp:Datatype "Code"Semantic MediaWiki
_dat
DateHolds particular points in timeTypes/DateHelp:Datatype "Date"Semantic MediaWiki
_ema
EmailHolds e-mail addressesTypes/EmailHelp:Datatype "Email"Semantic MediaWiki
_eid
External identifierHolds a value that associates it with with a external URI for formattingTypes/External identifierHelp:Datatype "External identifier"Semantic MediaWiki
_geo
Geographic coordinatesHolds coordinates describing geographic locationsTypes/Geographic coordinatesHelp:Datatype "Geographic coordinates"Maps (Semantic Maps)
_mlt_rec
Monolingual textHolds a text value that associates the annotation with a specific language codeTypes/Monolingual textHelp:Datatype "Monolingual text"Semantic MediaWiki
_num
NumberHolds integer and decimal numbers, with an optional exponentTypes/NumberHelp:Datatype "Number"Semantic MediaWiki
_wpg
PageHolds names of wiki pages, and displays them as a linkTypes/PageHelp:Datatype "Page"Semantic MediaWiki
_qty
QuantityHolds values that describe quantities, containing both a number and a unitTypes/QuantityHelp:Datatype "Quantity"Semantic MediaWiki
_rec
RecordHolds compound property values that consist of a short list of values with fixed type and orderTypes/RecordHelp:Datatype "Record"Semantic MediaWiki
_tel
Telephone numberHolds international telephone numbers based on the RFC 3966 standardTypes/Telephone numberHelp:Datatype "Telephone number"Semantic MediaWiki
_tem
TemperatureHolds temperature values (similar to type Quantity)Types/TemperatureHelp:Datatype "Temperature"Semantic MediaWiki
_txt
TextHolds text of arbitrary lengthTypes/TextHelp:Datatype "Text"Semantic MediaWiki
_ref_rec
ReferenceHolds a value that associates it to individual defined provenance metadata recordTypes/ReferenceHelp:Datatype "Reference"Semantic MediaWiki
_uri
URLHolds URIs, URNs and URLsTypes/URLHelp:Datatype "URL"Semantic MediaWiki