JSONCodec (json_codec v0.1.0)

Copy Markdown View Source

Compile-time generated codecs for JSON-shaped Elixir structs.

JSONCodec is not a JSON parser. It uses Jason for JSON parsing and focuses on the part application code usually repeats by hand: turning decoded string-keyed maps into nested structs with defaults, aliases, computed fields, explicit atom policy, and schema export.

Summary

Functions

Decodes a JSON string into module.

Decodes a JSON string into module, raising on failure.

Builds module from a decoded JSON map.

Builds module from a decoded JSON map, raising on failure.

Returns a JSON Schema-compatible schema map for a JSONCodec module.

Converts a struct or value into JSON-shaped Elixir data.

Functions

codec(name, opts)

(macro)

computed(name, fun_ast)

(macro)

decode(json, module)

Decodes a JSON string into module.

decode!(json, module)

Decodes a JSON string into module, raising on failure.

defstruct(fields)

(macro)

from_map(map, module)

Builds module from a decoded JSON map.

from_map!(map, module)

Builds module from a decoded JSON map, raising on failure.

json_schema(module)

Returns a JSON Schema-compatible schema map for a JSONCodec module.

to_map(value)

Converts a struct or value into JSON-shaped Elixir data.