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 Overflownpm
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
Repository https://github.com/mac-s-g/react-json-view
Pretty Printing JSON with React
The 'react-json-view' provides solution rendering json string. More on 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
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
Open Source JSON Viewer with styled-components
Github link
More on reddit.comVideos
05:22
#3 Try REACTJS Tutorial - Display Json Data - YouTube
14:18
Build a React.js JSON Viewer & Editor App to Render JSON ...
How to Pretty Print JSON | React Tutorial
14:40
JSON Viewer App | React JS - YouTube
Display Data from JSON File in React JS
01:12
How to Pretty Print JSON | React Tutorial - YouTube
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
Repository https://github.com/YYsuni/react18-json-view
Top answer 1 of 7
375
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>));
2 of 7
64
TLDR
Pretty Print JSON in JavaScript and React
<pre>{JSON.stringify(data, null, 2)}</pre>
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 ·
Reddit
reddit.com › r/reactjs › which json viewer component do you recommend since react-json-view no one maintains it anymore.
r/reactjs on Reddit: Which JSON Viewer Component do you recommend since react-json-view no one maintains it anymore.
October 16, 2023 -
https://www.npmjs.com/package/react-json-view?activeTab=versions
It was last updated 3 years ago.
I am looking for a popular alternative to that.
Thanks.
UNPKG
unpkg.com › react-json-viewer
react-json-viewer
React JSON Viewer Component.
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
Repository https://github.com/uiwjs/react-json-view
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%
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.