URL-encodes the contents of a string field.

ParameterTypeRequiredDefault ValueDescription
asstringoptional[a] _urlencode Name of output field.
field[b]stringrequired   The name of the input field with the value to url-encode.
typestringoptional[a]   Type of encoding.

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name field can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

urlEncode() Syntax Examples

With an event with a field Bar=https://www.example.com, you get https%3A%2F%2Fwww.example.com in the _urlencode field

logscale
urlEncode("Bar")

With an event with a field Bar=https://www.example.com, you get https%3A%2F%2Fwww.example.com in the Foo field

logscale
Foo:=urlEncode("Bar")

With an event with a field Bar=https://www.example.com, you get https%3A%2F%2Fwww.example.com in the Foo field

logscale
urlEncode("Bar", as="Foo")

urlEncode() Examples

Click + next to an example below to get the full details.

Convert Special Characters and Spaces in HTML Parsed Data

Convert special characters in strings to their percent-encoded equivalents using the urlEncode() function

Query
logscale
Bar = *
| urlEncode(field=Bar)
Introduction

URL encoding is necessary when processing data passed via HTML forms, as such data may contain special characters (like /, ., #) that could, for example, have special meanings in URLs, be invalid characters for URLs or be altered during transfer.

In this example, the urlEncode() function URL-encodes the content of the input field Bar and returns the result in the default output field _urlencode.

Example incoming data might look like this:

@timestampBarform_idsource
1683000000000https://www.example.comform_1web_submission
1683000001000https://internal.example.com/path#sectionform_2api_call
1683000002000https://search.example.com/?q=test queryform_3search_form
Step-by-Step
  1. Starting with the source repository events.

  2. logscale
    Bar = *

    Filters for events containing the Bar field.

  3. logscale
    | urlEncode(field=Bar)

    URL-encodes the content of the input field Bar and returns the result in the default output field _urlencode. Special characters are replaced with their percent-encoded ASCII equivalents.

  4. Event Result set.

Summary and Results

The query is used to convert special characters and spaces in data to their corresponding percent-encoded ASCII characters that, otherwise, could cause issues when being parsed. URL encoding replaces special characters with a percent sign (%) followed by a two-digit hexadecimal code that represents the character.

URL encoding is an important technique for ensuring that URLs can be transmitted and processed correctly, without issues caused by disallowed characters. It is commonly used in web applications, APIs, and other internet-based systems that work with URLs.

Sample output from the incoming example data:

@timestampBarform_idsource_urlencode
1683000000000https://www.example.comform_1web_submissionhttps%3A%2F%2Fwww.example.com
1683000001000https://internal.example.com/path#sectionform_2api_callhttps%3A%2F%2Finternal.example.com%2Fpath%23section
1683000002000https://search.example.com/?q=test queryform_3search_formhttps%3A%2F%2Fsearch.example.com%2F%3Fq%3Dtest%20query

Alternative ways to specify the output field is to use the assignment operator (Foo:=urlEncode("Bar") or the as parameter (urlEncode("Bar", as="Foo").