What is the best way to display JSON in Vaadin 14?

Hi,

I am using an Anchor to display a popup window (Dialog). On this dialog I want to show JSON output, which is stored in a String.
I have tried using label. But it displays the JSON in normal paragraph even though my json string contains \n. I want the output as JSON native look.
What is the best possible way to achieve this in vaadin 14?

If you want to render newline characters, can use the white-space CSS property. Either through CSS or directly in the element’s Style:

        Paragraph p = new Paragraph("this text\nhas\nsome line breaks");
        p.getElement().getStyle().set("white-space", "pre");
        add(p);

See https://developer.mozilla.org/en-US/docs/Web/CSS/white-space for more info.

Olli Tietäväinen:
If you want to render newline characters, can use the white-space CSS property. Either through CSS or directly in the element’s Style:

        Paragraph p = new Paragraph("this text\nhas\nsome line breaks");
        p.getElement().getStyle().set("white-space", "pre");
        add(p);

See https://developer.mozilla.org/en-US/docs/Web/CSS/white-space for more info.

That worked perfectly. You saved my day. Thank you very much !!