10

Is there a way to view JSON in a pretty format with lines wrapped when selecting the column in DataGrip? In MySQL Workbench there's a nice option of "Open value in Editor". The "Edit Maximized" does not wrap or fit in screen.

DataGrip: enter image description here

MySQL Workbench enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
John Jai
  • 3,463
  • 6
  • 25
  • 32

4 Answers4

12

You can use the Value Editor function which is available in the output panel of DataGrip.

enter image description here

When it's opened and you click on a cell in JSON format, the JSON will be shown prettified in the box.

enter image description here

Joe Cheng
  • 8,804
  • 3
  • 26
  • 25
11

At the moment you need to invoke Reformat code action when you're inside a cell.

Before: before

After reformat: after

Follow the issue DBE-6670

Update: Starting from 2020.3 Toggle Formatting button in cells Value Editor (right-click on cell, choose Maximize) The formatting mode is available for one-line JSON and XML values. It's turned on by default.

Konstantin Annikov
  • 11,655
  • 4
  • 27
  • 40
Vasilii Chernov
  • 1,169
  • 8
  • 17
  • 1
    Thanks, at least I can see it pretty though had to undo the formatting changes. It's good that Jetbrains is actively pursuing the issue now. – John Jai May 10 '20 at 00:22
  • 5
    Yes, we (DataGrip) hope to have the pretty viewer in 2020.2 – moscas May 12 '20 at 08:11
3

DataGrip 2022.2.2 here.

Staying in the sell of type "text" and formatting by CTRL+ALT+L didn't work for me. A message saying that the content is already formatted popped up. This only worked when I change the column type to "json".

What has worked for a regular text column is opening the Value Editor by Shift+Enter, then inside the editor right-clicking on an empty space and setting JSON as the formatting language by choosing "Set Highlighting Language..." in the popped-up menu.

enter image description here

Oleg
  • 187
  • 3
  • 5
0

Alternatively and if you use PostgreSQL, you can do pretty-format right in the query. Assume items column is a jsonb column:

select id, active, jsonb_pretty(items::jsonb) from orders;
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183