You'll need to either insert BR tag appropriately in the resulting string, or use for example a PRE tag so that the formatting of the stringify is retained:

var data = { a: 1, b: 2 };

var Hello = React.createClass({
    render: function() {
        return <div><pre>{JSON.stringify(data, null, 2) }</pre></div>;
    }
});

React.render(<Hello />, document.getElementById('container'));

Working example.

Update

class PrettyPrintJson extends React.Component {
    render() {
         // data could be a prop for example
         // const { data } = this.props;
         return (<div><pre>{JSON.stringify(data, null, 2) }</pre></div>);
    }
}

ReactDOM.render(<PrettyPrintJson/>, document.getElementById('container'));

Stateless Functional component, React .14 or higher

const PrettyPrintJson = ({data}) => {
    // (destructured) data could be a prop for example
    return (<div><pre>{ JSON.stringify(data, null, 2) }</pre></div>);
}

Or, ...

const PrettyPrintJson = ({data}) => (<div><pre>{ 
    JSON.stringify(data, null, 2) }</pre></div>);

Working example

Memo / 16.6+

(You might even want to use a memo, 16.6+)

const PrettyPrintJson = React.memo(({data}) => (<div><pre>{
    JSON.stringify(data, null, 2) }</pre></div>));
Answer from WiredPrairie on Stack Overflow
🌐
npm
npmjs.com › package › react-json-pretty
react-json-pretty - npm
Latest version: 2.2.0, last published: 6 years ago. Start using react-json-pretty in your project by running `npm i react-json-pretty`. There are 124 other projects in the npm registry using react-json-pretty.
      » npm install react-json-pretty
    
Published   Oct 14, 2019
Version   2.2.0
Author   chenckang@gmail.com
🌐
NGCC in Angular Ivy
iq.js.org › questions › react › how-to-pretty-print-json-with-react
How to pretty print JSON with React?
October 28, 2022 - To pretty print JSON with React, you can use the JSON.stringify() method and pass JSON object as the first argument, null as the second argument, and the 2 as the third argument.
🌐
GitHub
github.com › chenckang › react-json-pretty
GitHub - chenckang/react-json-pretty: A react component for prettifying JSON in browser
<JSONPretty id="json-pretty" style={{fontSize: "1.1em"}} data={youJSON} mainStyle="padding:1em" valueStyle="font-size:1.5em"></JSONPretty> Use onJSONPrettyError function property to get JSON.parse errors. <JSONPretty data={invalid} onJSONPrettyError={e => console.error(e)}></JSONPretty> Actually, react-json-pretty is based on JSON.stringify(value[, replacer[, space]]).
Starred by 160 users
Forked by 24 users
Languages   JavaScript 98.2% | TypeScript 1.6% | JavaScript 98.2% | TypeScript 1.6%
🌐
DEV Community
dev.to › gauravadhikari1997 › show-json-as-pretty-print-with-syntax-highlighting-3jpm
Show JSON As Pretty Print With Syntax Highlighting in React - DEV Community
June 24, 2025 - Now we can use our syntaxHighlight function, just pass it with JSON to prettify and highlight ... import { useEffect, useState } from "react"; import { syntaxHighlight } from "./utils"; import "./styles.css"; export default function App() { ...
🌐
CodeSandbox
codesandbox.io › examples › package › react-json-pretty
react-json-pretty examples - CodeSandbox
Use this online react-json-pretty playground to view and fork react-json-pretty example apps and templates on CodeSandbox.
🌐
DevQA
devqa.io › pretty-print-json-react
How to Pretty Print JSON with React
To pretty print JSON with React, you can use the JSON.stringify() method. By passing a JSON object as the first argument, null as the second, and t...
🌐
GitHub
github.com › GuillaumeCisco › react-json-prettify
GitHub - GuillaumeCisco/react-json-prettify: Simple and Lightweight React Component for displaying Json
import JSONPretty from 'react-json-prettify'; const json = { name: 'John Doe', age: 20, admin: true, member: null, permissions: ['read', 'write', 'edit'], deep: [ { a: { b: { c: null, d: ['e', 'f', [1, null]], }, }, }, ], }; return <JSONPretty json={json} /> Output will look like ·
Author   GuillaumeCisco
Find elsewhere
🌐
DhiWise
dhiwise.com › post › step-by-step-guide-implementing-react-json-formatter
A Comprehensive Guide to React JSON Formatter
September 5, 2024 - To beautify JSON data in a React component, you can use the JSON.stringify method with its second argument set to null for the replacer function, and the third argument used to define the number of spaces in the string representation of the JSON data...
🌐
C# Corner
c-sharpcorner.com › article › how-to-pretty-print-json-with-reactjs
How to Pretty Print JSON with ReactJS
May 24, 2024 - Pretty printing JSON in ReactJS enhances readability by formatting data with proper indentation. Utilizing JSON.stringify and React components, here's a comprehensive guide for implementation and styling.
🌐
YouTube
youtube.com › watch
How to Pretty Print JSON | React Tutorial - YouTube
How to Pretty Print JSONFree crash courses:React JWT Authentication: https://youtu.be/T5dIjye4b-IReact Redux: https://youtu.be/RPFr-hiFiU0React Redux Saga: h...
Published   July 29, 2023
🌐
GitHub
github.com › tanmancan › react-json-print
GitHub - tanmancan/react-json-print: React component that pretty prints JSON object in a collapsible tree view
Pretty prints JSON object in a collapsible tree view. A Vue.js verion is available here · Demo: https://tanmancan.github.io/examples/react-json-print/
Starred by 7 users
Forked by 2 users
Languages   JavaScript 76.4% | TypeScript 20.0% | HTML 2.1% | CSS 1.5% | JavaScript 76.4% | TypeScript 20.0% | HTML 2.1% | CSS 1.5%
🌐
YouTube
youtube.com › watch
How to Render JSON in React | Custom Pretty-Print Component Tutorial - YouTube
🚀 Learn how to render JSON data CLEANLY in React using a custom component! In this tutorial, I’ll walk you through building a reusable PrintJson component t...
Published   May 20, 2025
🌐
Techboxweb
techboxweb.com › how-to-pretty-print-json-in-react
How to pretty print JSON in react? - TechBoxWeb
Next Js is a very powerful react framework that lets you render React on the server side. Next Js comes with a lot… · September 5, 2020Comments Off on How to pretty print JSON in react?
🌐
GitHub
github.com › loopmode › react-pretty-json
GitHub - loopmode/react-pretty-json: A react component that pretty-prints JSON data, based on http://jsfiddle.net/unlsj/ · GitHub
import React, { Component } from 'react'; import PrettyJson from '@loopmode/react-pretty-json'; export class App extends Component { state = { foo: "foo", bar: "bar", nested: { stuff: "we needed a nested value", some: Immutable.fromJS({ data: 'immutable as well!'
Author   loopmode
🌐
CopyProgramming
copyprogramming.com › howto › how-do-i-display-prettyprinted-json-in-a-react-component
How to Display Pretty-Printed JSON in React Components: Complete Guide for 2026
December 27, 2025 - React provides both built-in JavaScript ... and most straightforward method to display pretty-printed JSON in React is using the native JavaScript JSON.stringify() method combined with the HTML <pre> tag....
🌐
Medium
medium.com › coding-at-dawn › how-to-pretty-print-json-in-just-one-line-of-javascript-html-or-react-2e79edd2b7ee
How To Pretty Print JSON in Just One Line of JavaScript + HTML (or React) | by Dr. Derek Austin 🥳 | Coding at Dawn | Medium
January 6, 2023 - How To Pretty Print JSON in Just One Line of JavaScript + HTML (or React) Ever need to debug a giant JSON object while working on frontend development? I’ve got you covered. When you’re …
🌐
npm
npmjs.com › package › react-json-formatter
react-json-formatter - npm
import React from 'react' import JsonFormatter from 'react-json-formatter' const App = () => { const sample = `{ "string":"ABCDE", "number":1, "null":null, "boolean":true, "object":{ "string":"ABCDE", "number":1, "null":null, "boolean":true }, "array":[ 1, 2, 3, 4, { "string":"ABCDE", "number":1, "null":null, "boolean":true, "array":[ 1, 2, 3, 4, { "string":"ABCDE", "number":1, "null":null, "boolean":true } ] } ] } ` const jsonStyle = { propertyStyle: { color: 'red' }, stringStyle: { color: 'green' }, numberStyle: { color: 'darkorange' } } return <JsonFormatter json={sample} tabWith={4} jsonStyle={jsonStyle} /> } export default App
      » npm install react-json-formatter
    
Published   Jul 04, 2023
Version   0.4.0
Author   ronny1020