LiveSvelteGettext.JSON (LiveSvelteGettext v0.2.0)

View Source

Minimal JSON encoding that does not force a particular library on consumers.

LiveSvelte made Jason optional in 0.17.0 and defaults to Erlang's built-in :json module (OTP 27+). Hard-requiring Jason here would drag it back into applications that have deliberately dropped it, so we pick an encoder in this order:

  1. the module configured as config :live_svelte_gettext, :json_library
  2. Jason, if it is loaded
  3. :json from OTP 27+

The payload is a plain map of strings, so any of these produce identical output.

Summary

Functions

Encodes data as a JSON string.

Returns the encoder that encode!/1 will use.

Functions

encode!(data)

@spec encode!(term()) :: String.t()

Encodes data as a JSON string.

Raises if no encoder is available, which can only happen on OTP 26 or older with Jason absent.

encoder()

@spec encoder() :: {:library, module()} | :otp | :none

Returns the encoder that encode!/1 will use.

Exposed for diagnostics and tests.