Search code examples
pythonjsonpycharm

Is there a way to view a json file on multiple lines in pycharm?


My searches for this question have just resulted in finding questions where users ask about multiline strings. My question isn't about this.

Let's say I have a big dictionary saved in a json file. For instance something like this:

{name1: {attribute1: value1, attribute2: value2, attribute3: value3}, name2: {attribute1: value1, attribute2: value2, attribute3: value3}, name3: {attribute1: value1, attribute2: value2, attribute3: value3}}

For many people with many attributes, this becomes impossible to read properly if it is all printed on one line, as it is in pycharm. Is there a way to configure pycharm so that it shows this kind of data in a more readable way when I try and read it by opening the file itself? I am aware that I can write a function to pretty print this, or use json.dumps with specifying indent, but I want to know if this is possible in the actual editor. It would ideally look something like this:

{
    name1: {
                attribute1: value1,
                attribute2: value2,
                attribute3: value3
            },
    name2: {
                attribute1: value1,
                attribute2: value2,
                attribute3: value3
            },
    name3: {
                attribute1: value1,
                attribute2: value2,
                attribute3: value3
            }
}

Solution

  • If the Json is in a separate file, you can do Actions -> Reformat code.

    enter image description here

    Not sure if there's a way to do it on file opening though.