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-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
GitHub
github.com › chenckang › react-json-pretty
GitHub - chenckang/react-json-pretty: A react component for prettifying JSON in browser
This is a lightweight and tiny react component that helps you to format and prettify the JSON data. npm install --save react-json-pretty · The usage is quite simple, assuming that you already have an application using React.
Starred by 160 users
Forked by 24 users
Languages JavaScript 98.2% | TypeScript 1.6% | JavaScript 98.2% | TypeScript 1.6%
Videos
05:58
How to Render JSON in React | Custom Pretty-Print Component Tutorial ...
How to Pretty Print JSON | React Tutorial
00:11
Pretty Print JSON with React #shorts #react - YouTube
01:12
How to Pretty Print JSON | React Tutorial - YouTube
09:26
Working with JSON data in React.js | Part 27 | Introduction To ...
09:14
2 - Display JSON data on a Map using React Leaflet - React Leaflet ...
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
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>
npm
npmjs.com › package › react-json-formatter
react-json-formatter - npm
» npm install react-json-formatter
Published Jul 04, 2023
Version 0.4.0
Author ronny1020
npm
npmjs.com › package › react-json-prettify
react-json-prettify - npm
Latest version: 0.2.0, last published: 6 years ago. Start using react-json-prettify in your project by running `npm i react-json-prettify`. There are no other projects in the npm registry using react-json-prettify.
» npm install react-json-prettify
Published Feb 17, 2020
Version 0.2.0
Author Guillaume Cisco
npm
npmjs.com › package › react-json-view-lite
react-json-view-lite - npm
JSON viewer component for React focused on performance for large volume input while still providing few customiziation features. Latest version: 2.5.0, last published: 6 months ago.
» npm install react-json-view-lite
Published Sep 06, 2025
Version 2.5.0
Author AnyRoad
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.
npm
npmjs.com › package › react-json-view
react-json-view - npm
RJV is a React component for displaying and editing javascript arrays and JSON objects. This component provides a responsive interface for displaying arrays or JSON in a web browser.
» 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
npm
npmjs.com › package › @types › react-json-pretty
@types/react-json-pretty - npm
Stub TypeScript definitions entry for react-json-pretty, which provides its own types definitions. Latest version: 2.2.0, last published: 6 years ago. Start using @types/react-json-pretty in your project by running `npm i @types/react-json-pretty`. There is 1 other project in the npm registry ...
» npm install @types/react-json-pretty
Published Nov 06, 2019
Version 2.2.0
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/ example JSON from: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON ...
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%
npm
npmjs.com › package › react-pretty-json
react-pretty-json - npm
JSON to HTML generator with colors and collapsible brackets.. Latest version: 2.0.2, last published: 8 years ago. Start using react-pretty-json in your project by running `npm i react-pretty-json`. There is 1 other project in the npm registry using react-pretty-json.
» npm install react-pretty-json
Published Aug 17, 2016
Version 2.0.2
Author Martynas Zilinskas
GitHub
github.com › masoud-naji › NPM-json-pretty-Component
GitHub - masoud-naji/NPM-json-pretty-Component: JSON pretty Component , can use directly on React projects to show your json in textarea component with controlling font size and color of everything · GitHub
JSON pretty Component , can use directly on React projects to show your json in textarea component with controlling font size and color of everything - masoud-naji/NPM-json-pretty-Component
Author masoud-naji
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.
npm
npmjs.com › package › @uiw › react-json-view
@uiw/react-json-view - npm
import JsonView from '@uiw/react-json-view'; import JsonViewEditor from '@uiw/react-json-view/editor'; import { lightTheme } from '@uiw/react-json-view/light'; import { darkTheme } from '@uiw/react-json-view/dark'; import { TriangleArrow } from '@uiw/react-json-view/triangle-arrow'; import { TriangleSolidArrow } from '@uiw/react-json-view/triangle-solid-arrow';
» 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
Npm
npm.io › package › react-json-beautify
React-json-beautify NPM | npm.io
A react component for rendering JSON data as a tree structure. Based on vue-json-pretty.
Npm
npm.io › search › keyword:json-formatter
Json-formatter | npm.io
jsonjson-beautifybeautifyjson-prettifyprettifyjson-formatter1.0.1 • Published 6 years ago · Format string to a json like template. fmt2jsonformat2jsonjsonzjsontoJsonbeJsonstr2jsonstring2jsonstr-to-jsonstring-to-json3.0.6 • Published 10 months ago · Formatting json data to JSX of React ·
Npm
npm.io › package › react-json-pretty
React-json-pretty NPM | npm.io
This is a lightweight and tiny react component that helps you to format and prettify the JSON data.