ExSQL. Json
(exsql v0.1.1)
Copy Markdown
The json1 function family's data layer: a JSON parser/renderer over an
order-preserving representation, plus path navigation ($.a.b[0],
$[#-1]).
JSON values map to:
:null,true,false- numbers (integer, float, or preserved real literal token)
- strings (binaries)
{:array, [value]}{:object, [{key, value}]}— pairs in source/insertion order, as SQLite preserves object member order injson_objectand rewrites
Hand-rolled rather than JSON/:json because object member order is
observable in SQLite's output.
Summary
Functions
RFC 7386 MergePatch, as json_patch() implements it: patch objects merge
recursively (null members delete), anything else replaces the target.
Parses $, $.key, $."quoted key", $[2], $[#-1] paths.
Converts a JSON value to its SQL representation (leaves stay scalar, containers render).
The json_type() name for a JSON value.
Writes value at the path. :insert only creates missing leaves,
:replace only overwrites existing ones, :set does both. Missing
intermediate containers leave the document unchanged, as in SQLite.
Types
@type path_step() :: {:key, binary()} | {:index, non_neg_integer()} | {:last_offset, integer()}
@type t() :: :null | boolean() | number() | {:real_literal, binary()} | {:jsonb_integer_literal, 4, binary(), integer()} | {:jsonb_real_literal, 5 | 6, binary()} | {:jsonb_text, 10, binary()} | {:jsonb_escaped_text, 8 | 9, binary(), binary()} | binary() | {:array, [t()]} | {:object, [{object_key(), t()}]}
Functions
RFC 7386 MergePatch, as json_patch() implements it: patch objects merge
recursively (null members delete), anything else replaces the target.
@spec object_key_text(object_key()) :: binary()
Parses $, $.key, $."quoted key", $[2], $[#-1] paths.
@spec to_sql(t()) :: ExSQL.Value.t()
Converts a JSON value to its SQL representation (leaves stay scalar, containers render).
The json_type() name for a JSON value.
Writes value at the path. :insert only creates missing leaves,
:replace only overwrites existing ones, :set does both. Missing
intermediate containers leave the document unchanged, as in SQLite.