Instance Methodgrdb 7.3.0GRDB

jsonRepresentation(atPath:)

Returns a valid JSON string with the -> SQL operator.

SQLJSONExpressible.swift:369
iOS
16+
macOS
13.2+
tvOS
17+
watchOS
9+
func jsonRepresentation(atPath path: some SQLExpressible) -> SQLExpression

Parameters

path

A JSON path, or an JSON object field label, or an array index.

For example:

let info = JSONColumn("info")

// SELECT info -> 'firstName' FROM player
// → '"Arthur"'
let name = try Player
    .select(info.jsonRepresentation(atPath: "firstName"), as: String.self)
    .fetchOne(db)

// SELECT info -> 'address' FROM player
// → '{"street":"Rue de Belleville","city":"Paris"}'
let name = try Player
    .select(info.jsonRepresentation(atPath: "address"), as: String.self)
    .fetchOne(db)

Related SQL documentation: https://www.sqlite.org/json1.html#jptr