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
Discussions

Which JSON Viewer Component do you recommend since react-json-view no one maintains it anymore.
console.log(JSON.stringify(object, null, 2)) More on reddit.com
๐ŸŒ r/reactjs
22
19
October 16, 2023
Is there a way to make Jest format JSON objects?
If youโ€™re testing actual JSON vs expected JSON, youโ€™re effectively testing two strings. Jest wonโ€™t format that, itโ€™ll show you the two raw strings. Itโ€™s not digging into the properties to check equality because itโ€™s not parsing the JSON. If you test a real JavaScript object vs a real JavaScript object though, itโ€™ll give you a decent diff, showing you which properties match, which are different, which are missingโ€ฆ Behind the scenes, both checks are made with Object.is. If the JSON string check fails then Jest bails out and throws an assertion error. If the object check fails, then Jest will first recursively compare each actual object property to each expected property, produce a diff, then throw the assertion error. tldr test objects, not JSON More on reddit.com
๐ŸŒ r/react
8
4
August 7, 2024
React is slow, what now?

Just don't forget that optimizations comes at a cost and they also tend to increases complexity :)

More on reddit.com
๐ŸŒ r/reactjs
114
287
February 7, 2019
react-scrollbars-custom: The best React custom scrollbars component

Looks very similar to the more popular repo react-custom-scrollbars.

The demos look almost the same

http://malte-wessel.github.io/react-custom-scrollbars/

https://xobotyi.github.io/react-scrollbars-custom/

And the API also looks too similar. You made it, and you are calling it "The best React custom scrollbars component", but to me it looks like plagiarism.

What can you say for your defence?

More on reddit.com
๐ŸŒ r/reactjs
6
0
September 14, 2016
๐ŸŒ
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() { ...
๐ŸŒ
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'; import {github} from 'react-json-prettify/themes'; 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} theme={github} padding={4} />
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 JSON data...
๐ŸŒ
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.