sql-formatter-org / sql-formatter-org/sql-formatter

Feature Request: Format `jsonb_build_object` as `key, value`

Open
#863 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature postgresql
Dominant language
TypeScript
Stars
2.9k
Forks
456
Avg merge
3d 4h
Merged PRs (30d)
3

Description

Describe the Feature

When writing JSONB, the standard formatting looks like this…

For me it is a lot easier to read when the key and values share line, like

jsonb_build_object('category', 'intersection_corner', 'size', 5) AS tags,
-- or
  jsonb_build_object(
    'size',
    ((tags ->> 'width')::float / 2)::float,
    'category',
    'driveway',
    'highway',
    tags ->> 'highway',
    'road',
    tags ->> 'road',
    'width',
    tags ->> 'width'
  ) AS tags,
  jsonb_build_object(
    /* sql-formatter-disable */
    'category', 'intersection_corner',
    'size', 5
    /* sql-formatter-enable */
  ) AS tags,
-- and
  jsonb_build_object(
    /* sql-formatter-disable */
    'size', ((tags ->> 'width')::float / 2)::float,
    'category', 'driveway',
    'highway', tags ->> 'highway',
    'road', tags ->> 'road',
    'width', tags ->> 'width'
    /* sql-formatter-enable */
  ) AS tags,

Why do you want this feature?

JSON always uses a key: value pattern to show it's data.
It would be a lot easier for me quickly parse the SQL if the formatter use a similar pattern (even though the jsonb_build_object lists all keys and values in one big list…)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name an implementation file, entry point, or test; begin by locating the formatter logic and existing tests for function-call arguments. Done means jsonb_build_object key/value arguments can be formatted on paired lines as requested without affecting other SQL formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.