Skip to content

Fetch JSON array created using datatypes.JSONSlice reported scan error: Failed to unmarshal JSONB value #97

@shelly-li-sl

Description

@shelly-li-sl

Fetch a JSON array inserted using the following codes reported scan error:

=== JSON Array:

type JsonGenericSliceOnly struct {
		ID     uint                         `gorm:"primaryKey;autoIncrement;column:record_id"`
		Name   string                       `gorm:"column:name"`
		Arr    datatypes.JSONSlice[string]  `gorm:"column:arr"`
		ArrPtr *datatypes.JSONSlice[string] `gorm:"column:arr_ptr"`
	}

=== Error reported:

2025/10/22 20:53:16 /scratch/shulili/GORM/gorm-github/gorm-oracle/tests/json_bulk_test.go:569 sql: Scan error on column index 2, name "arr": Failed to unmarshal JSONB value:["m","n","o"]
[4.652ms] [rows:1] SELECT * FROM "json_generic_slice_onlies" WHERE "record_id" = 1 ORDER BY "json_generic_slice_onlies"."record_id" FETCH NEXT 1 ROW ONLY
    json_bulk_test.go:570: reload failed: sql: Scan error on column index 2, name "arr": Failed to unmarshal JSONB value:["m","n","o"]
--- FAIL: TestJSONSlice (0.08s)

=== Full test case can be found in json_bulk_test.go(TestJSONSlice)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions