API reference@evolu/commonlocal‑first/Query › evoluJsonBuildObject

function evoluJsonBuildObject<O>(
  obj: O,
): RawBuilder<
  Simplify<{
    [K in string | number | symbol]: O[K] extends Expression<V> ? V : never;
  }>
>;

Defined in: packages/common/src/local-first/Query.ts:196

An improved Evolu version of Kysely's SQLite jsonBuildObject helper.

Kysely's ParseJSONResultsPlugin heuristically parses any result string that looks like JSON. Evolu instead prefixes JSON produced by these helpers with a per-runtime identifier and only parses values carrying that prefix, avoiding accidental parsing of ordinary string columns that merely happen to start with { or [.

Example

import { evoluJsonBuildObject, kyselySql } from "@evolu/common";

const result = await db
  .selectFrom("person")
  .select((eb) => [
    "id",
    evoluJsonBuildObject({
      first: eb.ref("first_name"),
      last: eb.ref("last_name"),
      full: kyselySql<string>`first_name || ' ' || last_name`,
    }).as("name"),
  ])
  .execute();

result[0]?.id;
result[0]?.name.first;
result[0]?.name.last;
result[0]?.name.full;