parse_json() converts a text column or string literal into a validated JSONB value so you can query it with native JSON operators.
parse_json() safely converts VARCHAR or TEXT that contains JSON into PostgreSQL’s JSONB type. This lets you run ->, ->>, and jsonb_path_* functions without first altering the table schema.
The function is a thin wrapper around PostgreSQL’s jsonb parser compiled into the ParadeDB extension.It returns NULL or throws an error when the input is not valid JSON, depending on the chosen mode.
See the next section for the complete signature, optional parameters, and default behaviors.
Use it in SELECTs, WHERE filters, or materialize its result into a generated column. Typical cases include ad-hoc reporting, backfills, or building a view on semi-structured ecommerce logs.
Yes.Pass the optional strict flag (‘strict’) to force the function to raise an exception instead of returning NULL on malformed JSON.
Lenient: SELECT parse_json(col) FROM raw_events; Strict: SELECT parse_json(col, 'strict') FROM raw_events;
The code example below converts the ‘metadata’ text column in Orders into JSONB and extracts the payment method.
Prefer casting once in a view or generated column.Index the generated JSONB expression with GIN if you filter frequently. Monitor failed parses via a NOT NULL check in STRICT mode.
See the mistakes section for quick fixes to typical errors like double-encoding or missing quotes.
.
No. It ships with the ParadeDB extension. Install it with CREATE EXTENSION paradedb;
Yes. Arrays are parsed into JSONB arrays and can be traversed with -> and ->> operators.
The function returns NULL, allowing the row to stay in the result set without breaking the query.