Page tree
Skip to end of metadata
Go to start of metadata

Often the JSON you receive does have a too complicated or irregular structure and cannot be displayed as a table directly. To make the styling easier, you can use a converter. Converters are pieces of JavaScript code that take the result from a query as JSON, process it into a custom array of objects and then pass it on to the template. Of course you can do some calculations, formattings and renamings there as well. 

Go to the converters' tab in the PocketQuery administration and add a new one. You can use the text button "Add converter scaffold" to help you get started. It gets interesting in line 9 where the script walks through each line of the original result set, extracts data from it and adds it to the new result in a different structure. Edit these lines to look like that:

result.push({ // add a converted object
	'Title': current.title,
	'Page ID': current.id,
	'Content Type': current.type
});

Save your converter. Next, go to the REST query, select the new converter from the dropdown and save.

Now, if you refresh your Confluence page with the PocketQuery macro, the resulting table should have changed into the structure build inside the converter:

Of course, you can also create a custom template to do even more styling. Whether or not you need the converter completely depends on the format of the JSON response of the REST API. Just keep in mind, that the template expects to get an array of objects and can not cope with arbitary JSON structures.

Want more? Continue with our "Templating Tutorial"

  • No labels