RustyJson.Sigil (rustyjson v0.3.9)

Copy Markdown View Source

JSON sigils for convenient JSON literals, compatible with Jason's Sigil module.

Sigils

  • ~j — Decodes a JSON string. Supports interpolation. Without interpolation, decoding happens at compile time.
  • ~J — Decodes a JSON string at compile time. No interpolation.

Modifiers

ModifierOption
akeys: :atoms
Akeys: :atoms!
rstrings: :reference
cstrings: :copy

Unknown modifiers raise ArgumentError.

Examples

import RustyJson.Sigil

~j({"name": "Alice", "age": 30})
#=> %{"name" => "Alice", "age" => 30}

~j({"name": "Alice"})a
#=> %{name: "Alice"}

~J({"x": 1, "y": 2})
#=> %{"x" => 1, "y" => 2}

Usage

Add import RustyJson.Sigil to use the sigils in your module.

Summary

Functions

Handles the ~J sigil for compile-time JSON decoding.

Handles the ~j sigil for JSON decoding.

Functions

sigil_J(arg, modifiers)

(macro)

Handles the ~J sigil for compile-time JSON decoding.

No interpolation is supported. Decoding always happens at compile time.

sigil_j(term, modifiers)

(macro)

Handles the ~j sigil for JSON decoding.

When the string has no interpolation, decoding happens at compile time. With interpolation, decoding happens at runtime.