(token: string): stringDecodes a JSON Pointer reference token according to RFC 6901 escaping rules.
When to use
Use when you need to decode a single escaped JSON Pointer path segment.
Details
- Returns a new unescaped string
- Replaces
~1with/(forward slash) and~0with~(tilde) - Returns the input unchanged if it contains no escaped sequences
- Empty strings are valid and returned unchanged
Gotchas
The replacement order matters: ~1 is replaced before ~0 to prevent incorrect decoding.
Example (Unescaping special characters)
import { JsonPointer } from "effect"
JsonPointer.unescapeToken("a~1b") // "a/b"
JsonPointer.unescapeToken("c~0d") // "c~d"
JsonPointer.unescapeToken("path~1to~0key") // "path/to~key"export function function unescapeToken(
token: string
): string
Decodes a JSON Pointer reference token according to RFC 6901 escaping rules.
When to use
Use when you need to decode a single escaped JSON Pointer path segment.
Details
- Returns a new unescaped string
- Replaces
~1 with / (forward slash) and ~0 with ~ (tilde)
- Returns the input unchanged if it contains no escaped sequences
- Empty strings are valid and returned unchanged
Gotchas
The replacement order matters: ~1 is replaced before ~0 to prevent incorrect decoding.
Example (Unescaping special characters)
import { JsonPointer } from "effect"
JsonPointer.unescapeToken("a~1b") // "a/b"
JsonPointer.unescapeToken("c~0d") // "c~d"
JsonPointer.unescapeToken("path~1to~0key") // "path/to~key"
unescapeToken(token: stringtoken: string): string {
return token: stringtoken.String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and
{@linkcode
replaceValue
}
to the [Symbol.replace] method on
{@linkcode
searchValue
}
. This method is expected to implement its own replacement algorithm.
replace(/~1/g, "/").String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and
{@linkcode
replaceValue
}
to the [Symbol.replace] method on
{@linkcode
searchValue
}
. This method is expected to implement its own replacement algorithm.
replace(/~0/g, "~")
}