Decode URL

About URL Encoding

What is URL encoding?

URL encoding converts characters into a format that can be transmitted over the Internet. Reserved and non-ASCII characters are replaced with a percent sign followed by two hexadecimal digits.

Why use URL encoding?

Use it when you need to safely include special characters in URLs, such as spaces, ?, &, or =. Otherwise URLs can break or be misread due to reserved characters.

URL Encoding in Bash

# Encoding
printf 'Hello, World!' | jq -sRr @uri
# Output: Hello%2C%20World%21

# Decoding
printf 'Hello%2C%20World%21' | jq -sRr @urid
# Output: Hello, World!
			

URL Encoding in JavaScript

// Encoding
let encoded = encodeURIComponent("Hello, World!");
console.log(encoded);
// Output: Hello%2C%20World%21

// Decoding
let decoded = decodeURIComponent("Hello%2C%20World%21");
console.log(decoded);
// Output: Hello, World!
			

URL Encoding in Go

package main
import (
	"fmt"
	"net/url"
)
func main() {
	// Encoding
	encoded := url.QueryEscape("Hello, World!")
	fmt.Println(encoded)
	// Output: Hello%2C+%21World%21 (QueryEscape uses + for spaces)

	// Decoding
	decoded, _ := url.QueryUnescape("Hello%2C%20World%21")
	fmt.Println(decoded)
	// Output: Hello, World!
}
			

URL Encoding in PHP

// Encoding
$encoded = urlencode("Hello, World!");
echo $encoded . "\n";
// Output: Hello%2C+%21World%21

// Decoding
$decoded = urldecode("Hello%2C%20World%21");
echo $decoded . "\n";
// Output: Hello, World!