psql JSON output format

Поиск
Список
Период
Сортировка
От Christoph Berg
Тема psql JSON output format
Дата
Msg-id ZYBdnGW0gKxXL5I_@msg.df7cb.de
обсуждение исходный текст
Ответы Re: psql JSON output format  (Christoph Berg <myon@debian.org>)
Re: psql JSON output format  (Jelte Fennema-Nio <postgres@jeltef.nl>)
Список pgsql-hackers
I noticed psql was lacking JSON formatting of query results which I
need for a follow-up patch. It also seems useful generally, so here's
a patch:

postgres=# \pset format json
Output format is json.
postgres=# select * from (values ('one', 2, 'three'), ('four', 5, 'six')) as sub(a, b, c);
[
{ "a": "one", "b": "2", "c": "three" },
{ "a": "four", "b": "5", "c": "six" }
]
postgres=# \x
Expanded display is on.
postgres=# select * from (values ('one', 2, 'three'), ('four', 5, 'six')) as sub(a, b, c);
[{
  "a": "one",
  "b": "2",
  "c": "three"
},{
  "a": "four",
  "b": "5",
  "c": "six"
}]
postgres=#

Both normal and expanded output format are optimized for readability
while still saving screen space.

Both formats output the same JSON structure, an array of objects.
Other variants like array-of-arrays or line-separated objects
("jsonline") might be possible, but I didn't want to overengineer it.

On the command line, the format is selected by `psql --json` and `psql -J`.
(I'm not attached to the short option, but -J was free and it's in
line with `psql -H` to select HTML.)

Christoph

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Stephen Frost
Дата:
Сообщение: Re: Detecting some cases of missing backup_label
Следующее
От: Christoph Berg
Дата:
Сообщение: Re: psql JSON output format