Summary
Follow-up of #3802, adding support for an array of Postgres JSON/JSONB objects from a query result.
Add a new postgres_object_array output transformation to the multi-strategy entity resolution service (service/entityresolution/multi-strategy/output_mapper.go) that converts a Postgres JSON/JSONB array-of-objects query result into a []map[string]any.
Postgres drivers may return JSON/JSONB array values as []byte, string, an already-parsed []map[string]any, or a []any whose elements are individually decodable as objects. Today, the output mapper has no dedicated transformation for these values, which forces awkward downstream handling when a mapping needs to surface a JSON/JSONB array column as a list of structured claims.
Motivation
When using a SQL-based provider in the multi-strategy ERS with a Postgres source, columns of type json/jsonb that hold an array of objects come back in one of several shapes depending on the driver. Consumers of the mapped claims expect a structured list of objects, not a raw byte slice, JSON-encoded string, or a []any of mixed shapes. A first-class postgres_object_array transformation removes that impedance mismatch and keeps mapping configuration declarative, mirroring the existing postgres_object transformation for single objects.
Proposed Behavior
Add postgres_object_array to the transformation switch in OutputMapper.applyTransformation:
nil → []map[string]any{} (empty array)
[]map[string]any → returned as-is (nil-safe: nil returns []map[string]any{})
[]any → each element is converted via transformPostgresObject; per-element errors are wrapped with the element index
[]byte → json.Unmarshal into []map[string]any; empty slice returns []
string → json.Unmarshal into []map[string]any; empty string returns []
- any other type → error with the concrete type in the message
Errors from json.Unmarshal are wrapped with context indicating the source type ([]byte vs string). Per-element conversion errors on []any inputs include the failing index.
Summary
Follow-up of #3802, adding support for an array of Postgres JSON/JSONB objects from a query result.
Add a new
postgres_object_arrayoutput transformation to the multi-strategy entity resolution service (service/entityresolution/multi-strategy/output_mapper.go) that converts a Postgres JSON/JSONB array-of-objects query result into a[]map[string]any.Postgres drivers may return JSON/JSONB array values as
[]byte,string, an already-parsed[]map[string]any, or a[]anywhose elements are individually decodable as objects. Today, the output mapper has no dedicated transformation for these values, which forces awkward downstream handling when a mapping needs to surface a JSON/JSONB array column as a list of structured claims.Motivation
When using a SQL-based provider in the multi-strategy ERS with a Postgres source, columns of type
json/jsonbthat hold an array of objects come back in one of several shapes depending on the driver. Consumers of the mapped claims expect a structured list of objects, not a raw byte slice, JSON-encoded string, or a[]anyof mixed shapes. A first-classpostgres_object_arraytransformation removes that impedance mismatch and keeps mapping configuration declarative, mirroring the existingpostgres_objecttransformation for single objects.Proposed Behavior
Add
postgres_object_arrayto the transformation switch inOutputMapper.applyTransformation:nil→[]map[string]any{}(empty array)[]map[string]any→ returned as-is (nil-safe: nil returns[]map[string]any{})[]any→ each element is converted viatransformPostgresObject; per-element errors are wrapped with the element index[]byte→json.Unmarshalinto[]map[string]any; empty slice returns[]string→json.Unmarshalinto[]map[string]any; empty string returns[]Errors from
json.Unmarshalare wrapped with context indicating the source type ([]bytevsstring). Per-element conversion errors on[]anyinputs include the failing index.