json-queries

command
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

README

JSON Queries

This example demonstrates JSON query functionality for querying and updating JSON columns in your database.

Features Demonstrated

  • Querying JSON fields for specific values using WhereJsonContains
  • Querying JSON arrays for values
  • Checking if JSON keys exist using WhereJsonContainsKey
  • Checking JSON array length using WhereJsonLength
  • Array indexing in JSON queries
  • Updating JSON fields with path notation
  • Combining multiple JSON query conditions

Running the Example

cd examples/json-queries
go run main.go

Running Tests

cd examples/json-queries
go test -v

Prerequisites

  • SQLite database (or modify the DSN to use your preferred database)
  • The example creates a products table with a JSON attributes column

Database Support

JSON query functions are supported for:

  • SQLite: Uses json_extract, json_type, and json_array_length functions
  • MySQL: Uses JSON_CONTAINS, JSON_CONTAINS_PATH, and JSON_LENGTH functions
  • PostgreSQL: Uses JSON functions (implementation may vary)

Example JSON Path Syntax

  • column->field - Access nested field
  • column->field->nested - Access deeply nested field
  • column->array->0 - Access array element by index

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL