Skip to main content
Skip table of contents

Filtering the Result of Your Query With a Converter

When we executed our first REST Query, the result looked like this:

Confluence page with REST data

This is because the JSON that we get from our Datasource contains a lot of values and even some lists or nested objects:

CODE
[
  {
    "name": {
      "common": "Portugal",
      "official": "Portuguese Republic",
      "nativeName": {
        "por": {
          "official": "República português",
          "common": "Portugal"
        }
      }
    },
    "tld": [
      ".pt"
    ],
    "cca2": "PT",
    "ccn3": "620",
    "cca3": "PRT",
    "cioc": "POR",
    // ... more data
  },
  // ... more data
]

Now, most of this data we actually don’t want to display in our table. There’s only a few fields out of these that we want. But how do we do this? Well, this is exactly what Converters are for. So, let’s go ahead and create one:

Converters tab in the PocketQuery administration

Converters are JavaScript functions that take in the raw result from your Datasource, operate on it, and return something else. The return value could for example be a sorted version of the data or a filtered version, just like in our case. Fill in the fields with these values:

Adding a Converter in PocketQuery

#

Field

Value

1

Name

REST Countries Filter

2

Content

JS
function convert(json) {
  return JSON.parse(json).map(country => {
	return {
	  'Flag': country.flag,
	  'Name': country.name.common,
	  'Code': country.cca2,
	  'Capital': country.capital && country.capital[0],
	  'Population': country.population
	}
  });
}

To make our Query use our newly created Converter, we have to go to the Queries tab and edit our “Countries per region“ Query. In the Query form, click on the Converter select box and choose our “REST Countries Filter” Converter:

Adding the Converter to your Query

After you have updated your Query, go back to your Confluence page and reload your page, to see what’s changed. Your table should now look like this:

Bildschirmfoto 2025-02-12 um 15.59.29.png

Ah, much better! Our table now displays exactly the columns we want. But how about if we want to change something about the layout and style in which the data is being displayed? If you’ve read “The PocketQuery Entities“ you probably know what comes next.

Continue with “Customizing the Appearance of Your Query With a Template

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.