Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Div
idProductTOC

On this page

Table of Contents
maxLevel1
excludeOn this page
typeflat
separatorpipe

Overview

JSON (JavaScript Object Notation) has become a highly used interchange format because of its lightweight, simplicity, and ability for humans to read and write easily. Many REST APIs produce JSON format and the format is used predominantly in Atlassian REST APIs. There is also an abundance of support libraries associated with the format which makes it ideal for scripting output. 

Excerpt

The JSON table macro can import, format and display JSON (JavaScript Object Notation) data from anywhere, by:

  • Reading the JSON data from any of these sources:
    1. Within your Confluence page.
    2. From a file residing on the Confluence server (Server only).
    3. From a Space Template (Server only).
    4. From a page attachment.
    5. From an external URL.
  • Allowing customizable access to fields.
  • Supporting inclusion of Wiki Markup macros within the JSON data.
  • Combining with the Chart macro to produce powerful data visualization.
  • Leveraging the same table styling capabilities as the Table Plus macro.

This macro supports Common table capabilities.

Tip

Available in plugin release 6.3 and above.


Basic Use

This macro can be deployed using one of the following methods:

Selected from the Macro BrowserJSON Table
Markup Shortcut{json-table}

Screenshot

Parameters

(info) Click a column heading to toggle the sorting of that column.

Table plus
highlightColor#ffffec
rowStylesbackground:#f0f0f0;color:#222;font-size:14px;border-bottom:black 2px solid;border-top:black 2px solid;,
stylebackground-color:white;
autoNumbertrue


Parameter
Default
Macro Browser Label
Description
paths<required>Paths to fields

Normally, specify a single path to generate a single table. Simple form is a dot separated list of field names to reach the specific field within the JSON string. Example: total.monthlies.

When a comma separated list of paths to fields is provided, a table will be produced for each valid field identified by the path. No table will be produced for references to fields that cannot be found, empty arrays, or similar.

Paths are expressed in JSONPath syntax.

fieldPathsall fieldsPaths to fields to be included

Comma separated list of paths to fields to be included in the output. Paths are relative to the JSON field specified in the paths parameter. If not specified, all fields found will be included.

Example for the issues field from the JIRA search REST API:
key, fields.summary, fields.issuetype.name, fields.issuetype.id, fields.fixVersions[*].name

fieldOrderRegexPatterns
Regex patterns for ordering fields

Comma separated list of regular expression (regex) patterns.

This parameter is used only when defaulting fieldPaths to all fields; otherwise the order specified by fieldPaths is used.

 Useful when multiple tables are generated and column ordering is not ideal. Field order is not specific in JSON strings so when field order is important, these Regex patterns can be used to control the order.

Note: A field found by an earlier pattern is ordered before fields not found or fields found by a later pattern.

sortPaths
Paths used to determine sort order

Comma separated list of path references to fields (simple only) to be used to determine how rows will be initially sorted.

Paths are relative to the JSON field specified in the path parameter. If specified, JSON array elements will be sorted based on the comparison of field values represented by the paths. The first path is the primary sort value. Subsequent paths are used only if the first comparison is equal. The sort direction is ascending unless the sortDescending is selected. This sorting is done before the HTML is generated for display.

stripQualifiersfalseStrip leading qualifiers from generated headingsSince 6.5. Makes table heading columns look better by stripping leading qualifiers (using a . separator) for names generated as a result of fieldPaths. For example, field.type would be converted to type.
capitalizetrueCapitalize first character of generated headingsSince 6.5. Makes table heading columns look better by capitalizing leading character of names generated as a result of fieldPaths.
outputhtmlOutput format

Determines how the output is formatted. Allowable values are 'html' and 'wiki'.

Use 'wiki' to have the data in the table rendered by the wiki renderer.

scriptmacro bodyLocation of JSON data

JSON data is taken from the macro body data unless another location is specified by the script or url parameters.

  • ^attachment - Data is read from an attachment to the current page.
  • page^attachment - Data is read from an attachment to the page name provided.
  • space:page^attachment - Data is read from an attachment to the page name provided in the space indicated.

Additional options available for Server only.

  • #filename - Data is read from the file located in confluence home directory/script/filename. Subdirectories can be specified.
  • global page template name - Data is read from a global page template. (info) Special note: How to deal with templates on Confluence 4.3 and later.
  • space:page template name - Data is read from a space template.
url
URL to JSON data Specifies the URL to a JSON file. Use of this parameter may be restricted for security reasons. See your administrator for details.
user
URL user User name for URL access via basic authentication.
password
URL user password User password for URL access via basic authentication. 
timeout
URL connection timeoutAllows you to set the wait time for URL access for slower connections. Time is specified in milliseconds.
encoding
File encoding

File encoding for an external file if different from the system default handling. Since 4.1.0.

Example: UTF-8

More ...

columns
Columns to showComma separated list of column names or numbers in any order. Defaults to all columns in existing order. Columns are enumerated starting at 1.
showWikifalse

Show non-formatted version of generated wiki

Use true to show a non-formatted version of the wiki table following the formatted table.

This is used to help resolve formatting issues. It can also be used to convert JSON to Confluence markup by cut and paste.

escapefalse

Escape special wiki characters

When wiki output is requested (output=wiki), some special characters (like '|', '[', ']', '{', '}') in data may cause undesirable formatting of the table. Use true to allow these special characters to be escaped so that it will not affect the formatting. The default is false so that data that has wiki markup will be handled correctly.
macrosfalse

Render wiki markup macros in body

Set to true to render wiki markup macros found in the body prior to processing as JSON.

This is useful to run macros from SCRP, CCLI, SQL, or similar that can produce JSON output.

disableAntiXssfalseStop encoding of html charactersServer only. Set this parameter to true for csv tables that use output=html and have html content. Html content like <a href=http://google.com>google</a> will only display as a link if this parameter is enabled. Your administrator must grant specific users or groups to use this capability using Macro Security for Confluence.


Augment parameters

See Augments for details for modifying column headings and column data.

Common parameters

Include Page
info:_CommonTableCapabilitiesParameters
info:_CommonTableCapabilitiesParameters

Examples

Content by Label
showLabelsfalse
spaces@self
showSpacefalse
sorttitle
operatorAND
cqllabel = "json_table" and label = "example" and space = currentSpace()
labelsexample,json_table

Compatibility

  • Chart Macro - the JSON Table Macro can be used to create data for a chart
  • Beanshell Macro - can be used to generate JSON Table Macro and data as output from Java code (use output=wiki)
  • Groovy Macro - can be used to generate JSON Table Macro and data as output from Groovy code (use output=wiki)
  • Jython Macro - can be used to generate JSON Table Macro and data as output from Jython code (use output=wiki)

Other Macros

Below is a list of all other Macros available within this Add-on:

Content by Label
showLabelsfalse
spaces@self
sorttitle
typepage
cqllabel = "macro_home" and type = "page" and space = currentSpace()
labelsmacro_home

Additional References

Include Page_SupportFooter_SupportFooter