SuperJSON.Path (superjson v0.1.0)

Copy Markdown View Source

Helper module for parsing and stringifying SuperJSON dot-notated and escaped path strings (e.g., "user.created_at", "items.0.name", "a\.1.b", "a\\\.1.b").

Summary

Functions

Parses a SuperJSON path string into a list of keys and Access.at/1 index structs.

Stringifies a list of keys and integers into a SuperJSON path string. Dots and backslashes in keys are escaped.

Functions

parse(path_string)

@spec parse(binary()) :: [binary() | (term() -> term())]

Parses a SuperJSON path string into a list of keys and Access.at/1 index structs.

Examples

iex> SuperJSON.Path.parse("a.b.c")
["a", "b", "c"]

iex> SuperJSON.Path.parse("items.0")
["items", Access.at(0)]

iex> SuperJSON.Path.parse("a\\.1.b")
["a.1", "b"]

stringify(path)

@spec stringify([binary() | integer()]) :: binary()

Stringifies a list of keys and integers into a SuperJSON path string. Dots and backslashes in keys are escaped.

Examples

iex> SuperJSON.Path.stringify(["a", 0, "b"])
"a.0.b"

iex> SuperJSON.Path.stringify(["a.1", "b"])
"a\\.1.b"