View Source Jason.Sigil (jason v1.4.1)

Link to this section Summary

Functions

Handles the sigil ~J for raw JSON strings.

Handles the sigil ~j for JSON strings.

Link to this section Functions

Link to this macro

sigil_J(term, modifiers)

View Source (macro)

Handles the sigil ~J for raw JSON strings.

Decodes a raw string ignoring Elixir interpolations and escape characters at compile-time.

examples

Examples

iex> ~J'"#{string}"'
"\#{string}"

iex> ~J'"\u0078\\y"'
"x\\y"

iex> ~J'{"#{key}": "#{}"}'a
%{"\#{key}": "\#{}"}
Link to this macro

sigil_j(term, modifiers)

View Source (macro)

Handles the sigil ~j for JSON strings.

Calls Jason.decode!/2 with modifiers mapped to options.

Given a string literal without interpolations, decodes the string at compile-time.

modifiers

Modifiers

See Jason.decode/2 for detailed descriptions.

  • a - equivalent to {:keys, :atoms} option
  • A - equivalent to {:keys, :atoms!} option
  • r - equivalent to {:strings, :reference} option
  • c - equivalent to {:strings, :copy} option

examples

Examples

iex> ~j"0"
0

iex> ~j"[1, 2, 3]"
[1, 2, 3]

iex> ~j'"string"'r
"string"

iex> ~j"{}"
%{}

iex> ~j'{"atom": "value"}'a
%{atom: "value"}

iex> ~j'{"#{:j}": #{'"j"'}}'A
%{j: "j"}