Dowser.Client.JSON (Dowser.Client v0.3.0)

View Source

JSON encoding and decoding, on Elixir's built-in JSON module.

No dependency and no choice to make: JSON ships with Elixir 1.18+, which dowser_client already requires.

Decoding always yields string-keyed maps, deliberately. Casting a response beyond plain JSON — atom keys, "2026-09-18" into ~D[2026-09-18] — needs to know which document each value came from and which mapping applies to it, which is backend-specific knowledge dowser_client doesn't have. That is an optional second pass over the decoded body, configured with :keys/:decoder; see Dowser.Client.Decoder.

Both functions return a Dowser.Client.JSON.Error rather than raising, so a malformed payload is an ordinary {:error, exception} result.

Summary

Functions

Decodes a JSON binary into a term with string keys.

Encodes term into JSON iodata.

Functions

decode(binary)

@spec decode(binary()) :: {:ok, term()} | {:error, Dowser.Client.JSON.Error.t()}

Decodes a JSON binary into a term with string keys.

encode(term)

@spec encode(term()) :: {:ok, iodata()} | {:error, Dowser.Client.JSON.Error.t()}

Encodes term into JSON iodata.