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-view
react-json-view - npm
March 9, 2021 - Interactive react component for displaying javascript arrays and JSON objects.. Latest version: 1.21.3, last published: 5 years ago. Start using react-json-view in your project by running `npm i react-json-view`. There are 903 other projects ...
      » npm install react-json-view
    
Published   Mar 09, 2021
Version   1.21.3
Author   Mac Gainor
Discussions

Pretty Printing JSON with React
The 'react-json-view' provides solution rendering json string. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - How to display the content of a JSON file in React? - Stack Overflow
I have a static JSON file in my public folder and I want to output the content in a React (NextJS) component. Simply display everything as JSON again. import data from '../../public/static/somedata... More on stackoverflow.com
🌐 stackoverflow.com
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
Open Source JSON Viewer with styled-components

Github link

More on reddit.com
🌐 r/reactjs
3
3
June 4, 2015
🌐
GitHub
github.com › microlinkhq › react-json-view
GitHub - microlinkhq/react-json-view: JSON viewer for React · GitHub
react-json-view (rjv) is a React component for displaying and editing javascript arrays and JSON objects.
Starred by 387 users
Forked by 69 users
Languages   JavaScript 99.5% | SCSS 0.5%
🌐
GitHub
github.com › uiwjs › react-json-view
uiwjs/react-json-view: A React component for displaying ...
September 13, 2022 - A React component for displaying and editing javascript arrays and JSON objects. - uiwjs/react-json-view
Starred by 402 users
Forked by 24 users
Languages   TypeScript 98.0% | HTML 2.0%
🌐
npm
npmjs.com › package › react18-json-view
react18-json-view - npm
February 19, 2025 - JSON viewer for react18. Latest version: 0.2.9, last published: a year ago. Start using react18-json-view in your project by running `npm i react18-json-view`. There are 53 other projects in the npm registry using react18-json-view.
      » npm install react18-json-view
    
Published   Feb 19, 2025
Version   0.2.9
Author   Suni
Find elsewhere
🌐
React Split
uiwjs.github.io › react-json-view
react-json-view
A React component for displaying and editing javascript arrays and JSON objects.
🌐
Stack Overflow
stackoverflow.com › questions › 68195357 › how-to-display-the-content-of-a-json-file-in-react
reactjs - How to display the content of a JSON file in React? - Stack Overflow
import data from '../../public/static/somedata/data.json'; const DummyComponent = () => { return ( <div className="box">{JSON.stringify(data)}</div> ); };
🌐
Transform
transform.tools › json-to-typescript
JSON to TypeScript
to React Native · to JSX · to Pug · to Big Query Schema · to Flow · to Go Bson · to Go Struct · to GraphQL · to io-ts · to Java · to JSDoc · to JSON Schema · to Kotlin · to MobX-State-Tree Model · to Mongoose Schema · to MySQL · to React PropTypes ·
🌐
npm
npmjs.com › package › @uiw › react-json-view
@uiw/react-json-view - npm
January 20, 2026 - JSON viewer for react.. Latest version: 2.0.0-alpha.41, last published: 2 months ago. Start using @uiw/react-json-view in your project by running `npm i @uiw/react-json-view`. There are 105 other projects in the npm registry using @uiw/react-json-view.
      » npm install @uiw/react-json-view
    
Published   Jan 20, 2026
Version   2.0.0-alpha.41
Author   Kenny Wang
🌐
GitHub
github.com › AnyRoad › react-json-view-lite
GitHub - AnyRoad/react-json-view-lite: Lightweight Json view component for React
react-json-view-lite is a tiny component for React allowing to render JSON as a tree. It focused on the balance between performance for large JSON inputs and functionality. It might not have all the rich features (suce as customization, copy, ...
Starred by 235 users
Forked by 25 users
Languages   TypeScript 95.9% | CSS 4.1% | TypeScript 95.9% | CSS 4.1%
🌐
DhiWise
dhiwise.com › post › mastering-data-visualization-with-react-json-viewer-components
Best Practices for Implementing a React JSON Viewer
September 5, 2024 - React JSON Viewer simplifies the process of displaying JSON data in a readable json format using a json viewer. It can handle various data types, including typeof undefined, typeof int, typeof null, typeof value, typeof float, typeof bigint, ...
🌐
npm
npmjs.com › package › react-json-view-lite
react-json-view-lite - npm
September 6, 2025 - react-json-view-lite is a tiny component for React allowing to render JSON as a tree. It focused on the balance between performance for large JSON inputs and functionality. It might not have all the rich features (suce as customization, copy, ...
      » npm install react-json-view-lite
    
Published   Sep 06, 2025
Version   2.5.0
Author   AnyRoad
🌐
GitHub
github.com › mac-s-g › react-json-view
GitHub - mac-s-g/react-json-view: JSON viewer for react · GitHub
JSON viewer for react. Contribute to mac-s-g/react-json-view development by creating an account on GitHub.
Starred by 3.7K users
Forked by 500 users
Languages   JavaScript 96.4% | Shell 2.9%
🌐
CodeSandbox
codesandbox.io › examples › package › react-json-view
react-json-view examples - CodeSandbox
AboutInteractive react component for displaying javascript arrays and JSON objects.753,229Weekly Downloads
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Load and Render JSON Data Into React Components | Pluralsight
April 1, 2025 - View plans · Contact sales · For individuals · For businesses · For public sector · This article explains how to fetch and render JSON data in React using the Fetch API or Axios, leveraging hooks like useState and useEffect for efficient state management.