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
A code formatting tool for raw json data. 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 ...
      » npm install react-json-pretty
    
Published   Oct 14, 2019
Version   2.2.0
Author   chenckang@gmail.com
🌐
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.
🌐
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
A react component that pretty-prints JSON data, based on http://jsfiddle.net/unlsj/ - loopmode/react-pretty-json
Author   loopmode
Find elsewhere
🌐
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() { const [ourJSON, setOurJSON] = useState(); useEffect(() => { fetch("https://jsonplaceholder.typicode.com/todos/1") .then((response) => response.json()) .then((json) => setOurJSON(json)); }, []); return ( <div> <h3 className="header"> Show JSON As Pretty Print With Syntax Highlighting </h3> <pre dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(ourJSON, undefined, 4)) }} /> </div> ); }
🌐
DevQA
devqa.io › pretty-print-json-react
How to Pretty Print JSON with React
October 7, 2023 - 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
🌐
npm Trends
npmtrends.com › react-json-pretty-vs-react-json-tree-vs-react-json-view-vs-react-json-viewer-vs-react-treeview
react-json-pretty vs react-json-tree vs react-json-view vs react-json-viewer vs react-treeview | npm trends
Comparing trends for react-json-pretty 2.2.0 which has 133,945 weekly downloads and 160 GitHub stars vs. react-json-tree 0.20.0 which has 892,897 weekly downloads and 14,338 GitHub stars vs. react-json-view 1.21.3 which has 1,086,291 weekly downloads and 3,665 GitHub stars vs. react-json-viewer ...
🌐
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 ...
🌐
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.
🌐
Bundlephobia
bundlephobia.com › package › react-json-pretty
react-json-pretty ❘ Bundlephobia
Find the size of javascript package react-json-pretty. Bundlephobia helps you find the performance impact of npm packages.
🌐
npm
npmjs.com › package › react-json-formatter
react-json-formatter - npm
July 4, 2023 - 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
🌐
CodeSandbox
codesandbox.io › s › react-json-prettify-demo-cjqz4
react-json-prettify demo - CodeSandbox
January 29, 2020 - react-json-prettify demo by GuillaumeCisco using react, react-dom, react-json-prettify, react-scripts
Published   Jan 13, 2020
Author   GuillaumeCisco
🌐
GitHub
github.com › chenckang › react-json-pretty › issues
chenckang/react-json-pretty
A react component for prettifying JSON in browser. Contribute to chenckang/react-json-pretty development by creating an account on GitHub.
Author   chenckang
🌐
YouTube
youtube.com › watch
How to Pretty Print JSON | React Tutorial
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
jsDelivr
jsdelivr.com › package › npm › react-json-pretty
react-json-pretty CDN by jsDelivr - A CDN for npm and GitHub
October 14, 2019 - A free, fast, and reliable CDN for react-json-pretty. A code formatting tool for raw json data
Published   Dec 29, 2015
🌐
C# Corner
c-sharpcorner.com › article › how-to-pretty-print-json-with-reactjs
How to Pretty Print JSON with ReactJS
May 24, 2024 - For this example, we will use a functional component. The JSON.stringify function can be used to convert a JavaScript object into a JSON string. To pretty-print, you pass additional arguments for spacing.