Skip to Content
ScriptingFilters

Filters

  • Function filters are useful for advanced data manipulation, and the syntax is inspired by Jinja Filters .
  • The filters can be used in Environment Variables and Tests.
  • The filter syntax is {{variable | filter1 | filter2...}} or, in Tests, json.items | filter1 | filter2....
  • If you’d like to use filters without a variable, use the @ sign: {{@ | filter1 | filter2}}.
  • Filters can be used in Headers, Body, Query Params, and Tests.

Filters in Environment Variables

  • This is useful for modifying the environment variable value before sending the request.
  • The filters can be used in Query Params, Headers, Auth, and Body.

img

Filters in Tests

  • This is useful for advanced use cases to test and set environment variables from the response.

img

Built-In Filters:

FunctionDescription
atThe filter will return element at index
absThe filter will return absolute value
addThe filter is useful to add number
atobThe filter will Base64 decode the value
btoaThe filter will Base64 encode the value
execThe filter will execute node command and return value (Paid version required)
firstThe filter will return first element in array
filterThe filter will perform array filter operation
formatThe format filter useful to format the string output
hashThe filter will create hash of the input
hmacThe filter will create hash of the input
isEmailThe filter will check the input is email or not and return true/false
isUrlThe filter will check the input is URL or not and return true/false
joinThe filter will join array with separator
lastThe filter will return last element in array
lengthThe filter will return length of the string or array
lowerThe filter will return lowercase of the string
mapThe filter will return subset of properties
multiplyThe filter is useful to multiply numbers
parseJSONThe filter will convert string to JSON object
propThe filter will get property value of an object
readFileThe filter will read the contents of the file (Paid version required)
removeQuotesThe filter will remove quotes from the string
removeSpacesThe filter will remove spaces from the string
replaceThe filter will replace match with replace string
setIfValueThe filter will set env variable only when input has value
setNullThe filter will set env variable value to null when the property value is null
sliceThe filter will perform standard array slice operation
splitThe filter will split the string using the separator
stringifyThe filter will JSON stringify the object
substringThe filter will return substring of the input
subtractThe filter will subtract number from input
uniqueThe filter will return unique elements in array
upperThe filter will return uppercase of the string
urlEncodeThe filter will encode the string
urlDecodeThe filter will decode the string

at

  • The filter returns the element at the at  index. The syntax in Tests is json.items | at(1).
  • If json.items value is [2,6,8,9], then:
    • json.items | at(1) the result will be 6
    • json.items | at(-1) the result will be 9

abs

  • The syntax is {{number | abs}}
  • If number value is -7, then the abs filter returns 7.

add

  • The syntax is {{number | add(5)}} or {{number | add("variableName")}}
  • You can pass parameter value as number or env variable name
  • e.g 1: if number value is 6, then add filter will return 11
  • e.g 2: if number is 5 and variable is 8, then result is 13

atob

  • The filter will decode  the value. The syntax is {{input | atob}}.
  • If input value is SGVsbG8gV29ybGQ=, then the result is Hello World.

btoa

  • The filter will Base64 encode  the value. The syntax is {{input | btoa}}.
  • If input value is Hello World, then the result is SGVsbG8gV29ybGQ=.

exec

This feature is available only in the paid version.
  • The filter executes a node command and returns the value. The syntax is {{variable | exec("command")}} or, without a variable, {{@ | exec("command")}}.
  • You can also pass variables as parameters e.g: {{@ | exec("gcloud auth {0} {1}", "var1", "var2")}}
  • If command value is node --version, then the result is v16.15.0.

first

  • The filter returns the first element in an array. The syntax in Tests is json.items | first.
  • If json.items value is [3,6,8,9], then the result is 3.

filter

  • The filter performs an array filter operation. The syntax in Tests is json.items | filter(id>5).
  • The following operations are supported: >, >=, <, <=, =, !=, *=, ^=, $=.
  • *= filters using contains operation
  • ^= filters using startsWith operation
  • $= filters using endsWith operation

format

  • The format filter is useful for formatting string output. The syntax is {{variable | format("Hello {0}")}}.
  • If variable value is World, then the result is Hello World.
  • Using multiple variables {{var1 | format("Hello {0} {1} {2}", "var2", "var3")}}, the {0} is replaced with var1 value, {1} with var2 value, and {2} with var3 value.
  • If you are using this in the Tests tab to set env values, you can use e.g. json.var1 | format("hello {0} {1}", "var2") in the left input.

hash

  • The filter creates a hash of the input. The syntax is {{variable | hash("algorithm", "encoding")}} or {{variable | hash}}.
  • @param - algorithm: The default value is MD5. The values supported are SHA256, SHA512, SHA1, MD5.
  • @param - encoding: The default value is base64. The values supported are hex, base64.

hmac

  • The filter creates a hash of the input. The syntax is {{variable | hmac("secret", "algorithm", "encoding")}} or {{variable | hmac("secret")}}.
  • @param - secret: The name of the env variable where secret is saved.
  • @param - algorithm: The default value is SHA256. The values supported are SHA256, SHA512, SHA1, MD5.
  • @param - encoding: The default value is base64. The values supported are hex, base64.

isEmail

  • The filter checks whether the input is an email and returns true or false. The syntax in Tests is json.email | isEmail.

isUrl

  • The filter checks whether the input is a URL and returns true or false. The syntax in Tests is json.homepage | isUrl.

join

  • The filter will join an array with a separator. The syntax is {{variable | split(" ") | join("separator")}} or in Tests json.items | join.
  • The default separator is comma ,, so you can use json.items | join.
  • If variable value is Hello World, then the result is Hello-World.

last

  • The filter returns the last element in an array. The syntax is json.items | last.
  • If json.items value is [3,6,8,9], then the result is 9.

length

  • The filter returns the length of the string or array. The syntax is {{variable | length}}.
  • If variable value is Hello World, then the result is 11.

lower

  • The filter returns the lowercase of the string. The syntax is {{variable | lower}}.
  • If variable value is Hello World, then the result is hello world.

map

  • The filter returns a subset of properties. The syntax is {{variable | map("id", "name")}} or in Tests json.items | map("id").
  • e.g 1: In Tests json.items | map("id"), which results in ["123","534","56444"].
  • e.g 2: json.items | map("id", "name"), which results in [{"name":"test1", "id":"123}, {"name":"test2", "id":"534"}].

multiply

  • The syntax is {{number | multiply(5)}} or {{number | multiply("variableName")}}
  • e.g 1: if number value is 6, then multiply filter will return 30
  • e.g 2: if number is 5 and variableName is 8, then result is 40

parseJSON

  • The filter converts a string to a JSON object. The syntax is {{address | parseJSON}}.
  • The filter can be used with other filters, e.g. {{address | parseJSON | prop("lat")}}.

prop

  • The filter gets a property value of an object. The syntax in Tests is json.items | prop("id").
  • e.g 1: If json.items value is [{"id":1005, "name":"boston"}], then prop("id") returns 1005.
  • e.g 2: If the array is [{"id":1005, "name":"boston"}, {"id":1006, "name":"london"}], then prop("id") returns 1005,1006.

readFile

This feature is available only in the paid version.
  • The filter reads the contents of the file. The syntax is {{pathVar | readFile}} or {{pathVar | readFile("base64")}}.
  • Create an env variable with the path of the file. The path can be absolute or relative to the workspace.
  • Relative paths work only if you enable the Save To Workspace setting.
  • e.g 1: {{pathVar | readFile}} reads the file as text, which is useful for reading JSON files.
  • e.g 2: {{pathVar | readFile("base64")}} reads the file as base64, which is useful for reading image files.
  • e.g 3: To use in the request body
{ "data": "{{pathVar | readFile(\"base64\")}}" }

removeQuotes

  • The filter removes quotes from the string. The syntax is {{variable | removeQuotes}}.
  • if variable value is "Hell"o W'orld, then result is Hello World

removeSpaces

  • The filter removes spaces from the string. The syntax is {{variable | removeSpaces}}.
  • if variable value is "Welcome Hello World, then the result is WelcomeHelloWorld

replace

  • The filter replaces a match with a replacement string. The syntax is {{variable | replace("Hello", "NewValue")}}.
  • If variable value is Hello World, then replace("Hello", "New") results in New World.
  • You can also pass a single argument, {{variable | replace("Hello")}}, which replaces with an empty string.

setIfValue

  • The filter sets an env variable only when the input has a value. The syntax in Tests is json.name | setIfValue.
  • This filter is useful in Tests section, when Set Env Variable dropdown selected

setNull

  • The filter sets the env variable value to null when the property value is null (by default null values are set as empty). The syntax in Tests is json.name | setNull.
  • This filter is useful in Tests section, when Set Env Variable dropdown selected

slice

  • The filter performs a standard array slice  operation. The syntax is {{variable | split(" ") | slice(1, 2)}}.
  • If variable value is welcome to thunder client, then the result is ["to"].

split

  • The filter splits the string using the separator. The syntax is {{variable | split("separator")}}.
  • If variable value is Hello World, then split(" ") results in ["Hello", "World"].

stringify

  • The filter JSON-stringifies the object. The syntax is {{variable | stringify}}.

substring

  • The filter returns a substring of the input. The syntax is {{variable | substring(start, end)}}.
  • If variable value is Hello World, then substring(-5) results in World.
  • If you want to pass input.length - 5, just pass -5.

subtract

  • The syntax is {{number | subtract(5)}} or {{number | subtract("variable")}}.
  • e.g 1: If number value is 6, then the subtract filter returns 1.
  • e.g 2: If number is 45 and variable is 8, then the result is 37.

unique

  • The filter returns unique elements in an array. The syntax is json.items | unique.
  • If json.items value is [3,8,9,6,8,9], then the result is [3,8,9,6].

upper

  • The filter returns the uppercase of the string. The syntax is {{variable | upper}}.
  • If variable value is Hello World, then the result is HELLO WORLD.

urlEncode

  • The filter will encode  the string. The syntax is {{queryParam1 | urlEncode}}.
  • If queryParam1 value is hello+world, then the result is hello%2Bworld.

urlDecode

  • The filter will decode  the string. The syntax is {{queryParam1 | urlDecode}}.
  • If queryParam1 value is hello%2Bworld, then the result is hello+world.
Last updated on