With our converter feature, you can use JavaScript to convert and extract data from any of your existing data sources. This can be especially helpful if the structure of your data source requires advanced functionality to prepare and output data optimally for your use case.

Please be aware that you should have basic JavaScript knowledge to use this function.

[Note: This feature is still in BETA ]

Create Data Source

To use the Converter function, you must add a new data source in addition to your existing data source. When creating this new data source, select the option Converter as Type. In the next step, select the data source whose data will be converted.

In our demo use case, this is a data source called "Expandable Dict" and it contains a very simple JSON data structure.

Javascript

Add JavaScript to convert the data according to your requirements.

You can always use the fixed variable datasource to access your underlying data source.

In our example, the original JSON looks like this:

{
 "result": [
   {e
    "id": 1,
    "title": "This is a product",
    "price:"" 1200,
    "category:" "Gadgets"
   },
   {
    "id": 2,
    "title": "Another product",
    "price:" 800,
    "category:" "Tools"
  }
 ] 
}
JSON

Return datasource is the simplest possible conversion script …

return datasource
CODE

… which outputs the data in the original JSON structure:

{
 "result": [
   {
    "id": 1,
    "title": "This is a product",
    "price:"" 1200,
    "category:" "Gadgets"
   },
   {
    "id": 2,
    "title": "Another product",
    "price:" 800,
    "category:" "Tools"
  }
 ] 
}
JSON

We can use built-in JavaScript methods like map, to convert the results to show the ID and product title as a simple list, for example:

return datasource.result.map(item => item.id + ' ' + item.title)
JS

Which will return the following JSON:

[
  "1 This is a product",
  "2 Another product"
]
JSON

* Note that result in the JS expression above is not a fixed variable like datasource. In our case, we use it to address our JSON list, because result is the name of our original JSON array that contains all products.

You can use map functions in different ways, like we did in our first example …

return datasource.result.map(item => ({ 
  id: item.id, 
  title: item.id + ' ' + item.title 
}))
JS

… to return a JSON output like this:

[
  {
    "id": 1,
    "title": "1 This is a product"
  },
  {
    "id": 2,
    "title": "2 Another product"
  }
]
JSON

Now let’s assume that we want to filter the results in a certain way; like, for example, that the JSON result only lists products with a price above 1000:

return datasource.result.filter(item => item.price > 1000)
JS

This would then return a list excluding all products priced below that threshold.

[
  {
    "id": 1,
    "title": "1 This is a product",
    "price:"" 1200,
    "category:" "Gadgets"
  },
]
JSON

Filter & map are generally very useful functions to manipulate lists of data, like shown in the examples above.

You can find more details on how to use JavaScript here.

Exposed Variables

This selection allows you to expose variables existing in your original data source.

Limitations

  • The original data source including the conversion script cannot exceed a maximum of 6 MB

  • The converted data cannot exceed a maximum of 6 MB

  • The script must return a result within 3 seconds

  • The conversion script itself cannot expose any variables. This might change in the future.

  • You cannot access contextual values like $.user or $.issue in the conversion script. This might be subject to change in the future.