JSON
JSON (JavaScript Object Notation) is one of the supported formats for data exchange. It is not only used internally by the software of MediaWiki core and many extensions, but with the help of third-party extensions the wiki itself can be a powerful vehicle for storing as well as working with JSON data. This page is about the latter.
JSON in the wiki
[edit]Content model
[edit]Wiki pages can have content models other than wikitext, including JSON. The simplest way to change the content model of a page to JSON is by going to 'Page information' and selecting JSON. See Manual:ContentHandler for more info.
JSON can also be stored separately in a content slot of the wiki page. For more information on content slots, see MCR.
Mixed content
[edit]Although it is seen much more rarely, there are also extensions that let you use a section of a wikitext page to contain JSON content. An example is Extension:TemplateData, which offers a tag templatedata
for describing a template and its parameters in the JSON format. Once stored, this information is made available (over the API) to extensions like VisualEditor.
Creating and editing JSON
[edit]General purpose:
- Extension:FlexForm - an extension for HTML5 forms which lets you create and edit JSON pages on the wiki. Supports JSON in content slots. FlexForm also supports the JSON format for creating the schema of a form.
- Extension:WSSlots - lets you set the default content model of a slot to JSON.
Special purpose:
- GeoJSON:
- Extension:Maps - lets you store GeoJSON in a dedicated namespace, with a Leaflet-based editor to edit maps, and lets you use GeoJSON data in maps.
- Extension:Kartographer supports inline GeoJSON within the mapframe tag
- Extension:JsonConfig - lets you store JSON on a wiki page in order for other extensions to store their configuration data as a JSON blob.
- Extension:TemplateData - lets you store data about your template in JSON, making them available for use by extensions like Extension:VisualEditor.
- Extension:PageProperties - lets you annotate JSON-LD (JSON for Linked Data) within a wiki page.
- Extension:IIIF - lets you work with JSON-LD for IIIF. See also Extension:Mirador.
Code language support and Syntax highlighting
[edit]Converting/exporting to JSON
[edit]Even when data are not necessarily stored in JSON, there are ways to retrieve them in that format.
- The MediaWiki API lets you interact with the wiki, using JSON as a primary format by appending
&format=json
to the URL. See also API:Data formats. - Extension:Semantic MediaWiki (SMW) - lets you use the wiki to store and query data in a database. Data can be exported in a number of result formats, including JSON. See e.g. the JSON result format and the JSON export function that comes with Datatables.
- Many extensions come with a custom API that lets you retrieve data in JSON, including SMW, Page Forms, FlexForm, TextExtracts, etc., etc. ...
- GoogleRichCards (beta) - generates Google Rich Cards in JSON-LD format
Reading and working with JSON
[edit]- Extension:Scribunto - adds Lua to your wiki and offers Lua functions to load, decode and encode JSON data. See the descriptions of mw.loadJsonData, mw.text.jsonDecode and mw.text.jsonEncode on Extension:Scribunto/Lua reference manual.
- Extension:WSSlots - can be used to fetch JSON content from a slot. Comes with functions for Lua.
- Extension:External Data - lets you query JSON from a URL or file on the server. Comes with support for JSONPath.
See also
[edit]- MediaWiki core
- Extension:JsonData