Part of the Phase 2 set of PostgreSQL-specific features beyond the built-in driver.
Problem
JSONB columns are currently edited as a raw text string. For complex nested objects this is error-prone — a single misplaced brace or quote produces an opaque parse failure, and there's no way to modify one nested key without retyping the entire value.
Proposed approach
This is primarily a frontend feature (UI extension); the plugin's role is narrow:
- Detect JSONB columns and flag them in the
get_columns response — already done (data_type: "jsonb").
- Validate JSON on
update_record — return a clear error (with position) if invalid JSON is submitted, instead of a bare Postgres parse error.
- Optionally expose
jsonb_set/jsonb_insert/jsonb_delete_path-style helper operations so the frontend can apply targeted edits.
Plugin-side additions
- New RPC method:
validate_jsonb(value) → returns ok, or a parse error with position.
- New RPC method:
jsonb_patch(params, table, pk, path, operation, value) → applies a targeted JSONB modification without overwriting the entire value.
Frontend integration
- JSON tree editor component (expand/collapse nodes, edit values inline).
- Add/remove key buttons.
- Path breadcrumb showing current location in the JSON tree.
- Raw mode toggle (switch between tree and text editor).
Security considerations
A jsonb_patch call with an incorrect path could corrupt data (e.g. overwriting the wrong nested key). The frontend should validate that the target path exists and show a preview of the resulting value before committing the patch.
Acceptance criteria
Tests
test_insert_complex_jsonb — nested objects, arrays, mixed types
test_update_jsonb_full_replace — overwrite entire value
test_jsonb_patch_add_key — add key to existing object
test_jsonb_patch_remove_key — remove key from object
test_jsonb_patch_nested_update — modify deeply nested value
test_invalid_jsonb_rejected — malformed JSON returns clear error
References
- Full spec:
docs/planning/03-phase-2-issue-16.md (2.2)
- Priority: Sprint 2 — high demand, more complex (UI extension)
- Required for the Phase 2 stable-release gate (CP-5)
Part of the Phase 2 set of PostgreSQL-specific features beyond the built-in driver.
Problem
JSONB columns are currently edited as a raw text string. For complex nested objects this is error-prone — a single misplaced brace or quote produces an opaque parse failure, and there's no way to modify one nested key without retyping the entire value.
Proposed approach
This is primarily a frontend feature (UI extension); the plugin's role is narrow:
get_columnsresponse — already done (data_type: "jsonb").update_record— return a clear error (with position) if invalid JSON is submitted, instead of a bare Postgres parse error.jsonb_set/jsonb_insert/jsonb_delete_path-style helper operations so the frontend can apply targeted edits.Plugin-side additions
validate_jsonb(value)→ returns ok, or a parse error with position.jsonb_patch(params, table, pk, path, operation, value)→ applies a targeted JSONB modification without overwriting the entire value.Frontend integration
Security considerations
A
jsonb_patchcall with an incorrect path could corrupt data (e.g. overwriting the wrong nested key). The frontend should validate that the target path exists and show a preview of the resulting value before committing the patch.Acceptance criteria
validate_jsonbrejects malformed JSON with a position-aware error, accepts valid JSONjsonb_patchcan add/remove/update a nested key without touching the rest of the documentTests
test_insert_complex_jsonb— nested objects, arrays, mixed typestest_update_jsonb_full_replace— overwrite entire valuetest_jsonb_patch_add_key— add key to existing objecttest_jsonb_patch_remove_key— remove key from objecttest_jsonb_patch_nested_update— modify deeply nested valuetest_invalid_jsonb_rejected— malformed JSON returns clear errorReferences
docs/planning/03-phase-2-issue-16.md(2.2)