Documentation
¶
Overview ¶
Package pgjson encodes and decodes the jsonb columns of a database that mongo2pg produced.
Why encoding/json is the wrong codec here ¶
mongo2pg writes a jsonb column as Mongo RELAXED EXTENDED JSON: field names come from the document as it existed in MongoDB — i.e. the Go model's `bson` tags — and a date is the object {"$date": "..."} rather than a bare string.
encoding/json reads the `json` tags instead, which on these models are the API-facing camelCase spellings. The two agree only where a field's bson and json tags happen to be identical. Everywhere else, decoding with encoding/json does not fail — it silently yields the zero value, because JSON simply has no such member. A user's `key_set` comes back with an empty userKey and a nil publicKey, and nothing anywhere reports an error.
That is why this package exists and why it is used for EVERY jsonb column rather than only the ones observed to break: "the tags match today" is not a property anyone maintains deliberately, and the failure is silent.
Writes use the same shape as replication ¶
Marshal deliberately emits the same extended-JSON shape mongo2pg writes, so a row this service inserts is indistinguishable from a replicated one. The alternative — reading one shape and writing another — leaves a column holding both, where correctness depends on which process happened to create each row.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.