JsonPointer.ts
JsonPointer.ts overview
Section titled “JsonPointer.ts overview”Escapes a JSON Pointer reference token according to RFC 6901 by encoding special characters so the token can be safely used as a segment in a JSON Pointer.
When to use
Use when you need to escape a single JSON Pointer path segment.
Details
- Returns a new escaped string
- Replaces
~(tilde) with~0and/(forward slash) with~1 - Returns the input unchanged if it contains no special characters
- Empty strings are valid and returned unchanged
Gotchas
The replacement order matters: ~ is replaced before / to prevent double-escaping.
Example (Escaping special characters)
import { JsonPointer } from "effect"
JsonPointer.escapeToken("a/b") // "a~1b"JsonPointer.escapeToken("c~d") // "c~0d"JsonPointer.escapeToken("path/to~key") // "path~1to~0key"See
unescapeTokenThe inverse operation for decoding escaped tokens
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”decoding
Section titled “decoding”unescapeToken
Section titled “unescapeToken”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
~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"See
escapeTokenThe inverse operation for encoding tokens
Signature
declare const unescapeToken: (token: string) => stringSince v4.0.0
encoding
Section titled “encoding”escapeToken
Section titled “escapeToken”Escapes a JSON Pointer reference token according to RFC 6901 by encoding special characters so the token can be safely used as a segment in a JSON Pointer.
When to use
Use when you need to escape a single JSON Pointer path segment.
Details
- Returns a new escaped string
- Replaces
~(tilde) with~0and/(forward slash) with~1 - Returns the input unchanged if it contains no special characters
- Empty strings are valid and returned unchanged
Gotchas
The replacement order matters: ~ is replaced before / to prevent double-escaping.
Example (Escaping special characters)
import { JsonPointer } from "effect"
JsonPointer.escapeToken("a/b") // "a~1b"JsonPointer.escapeToken("c~d") // "c~0d"JsonPointer.escapeToken("path/to~key") // "path~1to~0key"See
unescapeTokenThe inverse operation for decoding escaped tokens
Signature
declare const escapeToken: (token: string) => stringSince v4.0.0