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
| Modifier | Option |
|---|---|
a | keys: :atoms |
A | keys: :atoms! |
r | strings: :reference |
c | strings: :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
Handles the ~J sigil for compile-time JSON decoding.
No interpolation is supported. Decoding always happens at compile time.
Handles the ~j sigil for JSON decoding.
When the string has no interpolation, decoding happens at compile time. With interpolation, decoding happens at runtime.