DataPrime: URL decoding / encoding
This guide provides a glossary of IBM® Cloud Logs DataPrime URL functions for encoding and decoding URLs.
urlDecode and urlEncode support the function and the method notation.
urlEncode
Use urlEncode to convert characters into a format that can be transmitted over the Internet.
To send a URL over the Internet, the URL must be set using the ASCII character-set. For example, you might need to encode a set of characters and replace an empty space with %20.
Function
urlEncode(string: string): string
For example, you could use the following sample to encode the value of query_string_parameters.name by using a function:
replace query_string_parameters.name with urlEncode(query_string_parameters.name)
Method
string: string.urlEncode(): string
For example, you could use the following sample to encode the value of query_string_parameters.name by using a method:
replace query_string_parameters.name with query_string_parameters.name.urlEncode()
urlDecode
Use urlDecode to convert a URL into a format that is user friendly.
Function
urlDecode(string: string): string
For example, you could use the following sample to decode the value of query_string_parameters.name by using a function:
replace query_string_parameters.name with urlDecode(query_string_parameters.name)
Method
string: string.urlDecode(): string
For example, you could use the following sample to decode the value of query_string_parameters.name by using a method:
replace query_string_parameters.name with query_string_parameters.name.urlDecode()
Example: Converting the URL header parameters into a JSON Object and URL decoding
Consider the following log line:
{
"domain": "https://www.ibm.com",
"path": "/home",
"query_string": "name=My%20Name&b=c%20d&c=d"
}
First, extract each query string parameter into its own object field.
extract query_string into query_string_parameters using kv(pair_delimiter='&',key_delimiter='=')
The resulting document looks like this:
{
"domain":"https://www.ibm.com",
"query_string":"name=My%20Name&b=c%20d&c=d",
"path": "/home",
"query_string_parameters":{
"name":"My%20Name",
"b":"c%20d",
"c":"d"
}
}
Then, decode the query_string_parameters.name and replace %20 with an empty space. Use replace to overwrite the old field with a new one and overwrite the value of an existing keypath with a new one.
replace query_string_parameters.name with urlDecode(query_string_parameters.name)
replace query_string_parameters.b with urlDecode(query_string_parameters.b)
This results in the following document:
{
"domain":"https://www.ibm.com",
"query_string":"name=My%20Name&b=c%20d&c=d",
"path": "/home",
"query_string_parameters":{
"name":"My name",
"b":"c d",
"c":"d"
}
}