Selecto.Output.Transformers.Json (Selecto v0.3.8)

JSON transformer for Selecto query results.

Provides JSON serialization with configurable options for null handling, metadata inclusion, pretty printing, and streaming support for large datasets.

options

Options

  • :include_meta - Include query metadata in response (default: false)
  • :pretty - Pretty print JSON output (default: false)
  • :null_handling - How to handle nil values: :null, :omit, :empty_string (default: :null)
  • :keys - Key format: :strings, :atoms (default: :strings)
  • :coerce_types - Enable type coercion (default: false)
  • :date_format - Date serialization format: :iso8601, :unix, :string (default: :iso8601)
  • :decimal_format - Decimal format: :string, :float (default: :string)

examples

Examples

# Basic JSON serialization
{:ok, json} = Json.transform(rows, columns, %{}, [])

# JSON with metadata
{:ok, json} = Json.transform(rows, columns, %{}, [include_meta: true])

# Pretty printed JSON with null omission
{:ok, json} = Json.transform(rows, columns, %{}, [
  pretty: true,
  null_handling: :omit
])

# Streaming for large datasets
stream = Json.stream_transform(rows, columns, %{}, [pretty: true])

Link to this section Summary

Functions

Transform query results to a JSON stream for large datasets.

Transform query results to JSON string.

Link to this section Types

Link to this type

json_option()

@type json_option() ::
  {:include_meta, boolean()}
  | {:pretty, boolean()}
  | {:null_handling, :null | :omit | :empty_string}
  | {:keys, :strings | :atoms}
  | {:coerce_types, boolean()}
  | {:date_format, :iso8601 | :unix | :string}
  | {:decimal_format, :string | :float}
Link to this type

json_options()

@type json_options() :: [json_option()]

Link to this section Functions

Link to this function

stream_transform(rows, columns, aliases, options \\ [])

@spec stream_transform([list()] | Enumerable.t(), [String.t()], map(), json_options()) ::
  Enumerable.t()

Transform query results to a JSON stream for large datasets.

Returns a stream that yields JSON strings, useful for processing large result sets without loading everything into memory.

Link to this function

transform(rows, columns, aliases, options \\ [])

@spec transform([list()], [String.t()], map(), json_options()) ::
  {:ok, String.t()} | {:error, Selecto.Error.t()}

Transform query results to JSON string.

Returns a JSON string representation of the query results with configurable serialization options.