Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
Flask Python - How do make a newline on json format and return it as html?

I've been trying to make newline on JSON Format, but none of it doesn't work.

from flask import *
import json

app = Flask(__name__)


@app.route("/user/", methods=["GET"])
def user():
    datajson = {"Author": "Stawa", 
                "Version": "0.1.7"}
    json_format = json.dumps(datajson, indent=6)
    return render_template("index.html", json_format=json_format)

in index.html

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>TEST</title>
      <meta charset="utf-8">
   </head>
   <body>
      <p>{{ json_format }}</p>
   </body>
</html>

The out put was {"Author": "Stawa", "Version": "0.1.7"}, but I want to make it as

{
 "Author": "Stawa",
 "Version": "0.1.7"
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's because the browser interprets your JSON string as HTML, and it doesn't care about newline characters. To preserve formatting, you can use the HTML <pre> tag. I tested the following template with your code, and it displays the JSON on two lines. Hope it works on your computer as well!

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
   <head>
      <title>TEST</title>
      <meta charset="utf-8">
   </head>
   <body>
      <pre>{{ json_format }}</pre>
   </body>
</html>

Output:

Output

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!