JSONCodec (json_codec v0.3.1)

Copy Markdown View Source

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

JSONCodec is not a JSON parser. It parses with Elixir's JSON module on Elixir 1.18+, or Jason on earlier versions, 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.

Dumps a value into JSON-shaped Elixir data, respecting JSONCodec field names.

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.

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.

dump(value)

Dumps a value into JSON-shaped Elixir data, respecting JSONCodec field names.

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.

schema(module)

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