Skip to content

urlEncode - Encode a value for URL readiness

In order to transmit values within a URL, values should be URL encoded. In order to prepare data for further output, perhaps using Log Forwarders, URL encoding is a useful feature.

Syntax

urlEncode(string: string): string

Arguments

Name Type Required Description
string string true The string to URL encode

Example - URL encoding a string

Consider the following document:

{
  "domain": "https://www.coralogix.com",
  "path": "/home",
  "query_string": "name=Tom Kosman&b=c&c=d"
}

We want to extract each query string parameter into its own object field, which will give us the ability to query on individual query string fields. We can do this using kv.

extract query_string into query_string_parameters using kv(pair_delimiter='&',key_delimiter='=')

The resulting document looks like this:

{
  "domain":"https://www.coralogix.com",
  "query_string":"a=b&b=c&c=d",
  "path": "/home",
  "query_string_parameters":{
    "name":"Tom Kosman",
    "b":"c",
    "c":"d"
  }
}

We can see that the parameter name contains a space. We can fix this using urlEncode:

replace query_string_parameters.name with query_string_parameters.name.urlEncode()

This results in the following document:

{
  "domain":"https://www.coralogix.com",
  "query_string":"a=b&b=c&c=d",
  "path": "/home",
  "query_string_parameters":{
    "name":"Tom%20Kosman",
    "b":"c",
    "c":"d"
  }
}

Try it yourself

Open up your log explore screen, and paste in this dataprime query to see a working example of urlEncode:

create query_string_parameters.name from 'Tom Kosman' 
| choose query_string_parameters.name 
| replace query_string_parameters.name with query_string_parameters.name.urlEncode()