Transformer to filter API JSON response based on the value of one property

I have a restapi Query in my Query Library that returns a JSON list of servers with each property being details about each server, e.g.:

[
  {
    "id": 355,
    "serverIp": "10.10.10.1",
    "hostname": "server1",
    "serverType": "PS",
    "active": true,
  },
  {
    "id": 356,
    "serverIp": "10.10.10.5",
    "hostname": "server2",
    "serverType": "XSP",
    "active": true,
  },
  {
    "id": 355,
    "serverIp": "10.10.10.11",
    "hostname": "server3",
    "serverType": "XSP",
    "active": true,
  }
]

I would like to apply a transformer to the Resource (Import from the Query Library) such that only JSON objects returned by the Resource are servers where the "serverType" is equal to "XSP"

The returned value after the Transformer I am hoping for:

[
  {
    "id": 356,
    "serverIp": "10.10.10.5",
    "hostname": "server2",
    "serverType": "XSP",
    "active": true,
  },
  {
    "id": 355,
    "serverIp": "10.10.10.11",
    "hostname": "server3",
    "serverType": "XSP",
    "active": true,
  }
]

I have seen this article:

but I'm new to Retool and Java and I can't seem to modify it for my purposes and get it to return anything.

I very much appreciate any help!

@jonc Welcome to the community

Use a Query JSON with SQL against that result

I took your data and put it in a table but you could simply use {{originalqueryhere.data}} in stead of {{table3.data}}

select * from {{table3.data}} where serverType = 'XSP'

2 Likes

Wonderful. Thank you so much @ScottR ! I see how using the Query JSON with SQL is more elegant than a transformer.