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
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 react-json-pretty.
» npm install react-json-pretty
Published Oct 14, 2019
Version 2.2.0
Author chenckang@gmail.com
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>
Videos
GitHub
github.com › chenckang › react-json-pretty
GitHub - chenckang/react-json-pretty: A react component for prettifying JSON in browser
<JSONPretty id="json-pretty" style={{fontSize: "1.1em"}} data={youJSON} mainStyle="padding:1em" valueStyle="font-size:1.5em"></JSONPretty> Use onJSONPrettyError function property to get JSON.parse errors. <JSONPretty data={invalid} onJSONPrettyError={e => console.error(e)}></JSONPretty> Actually, react-json-pretty is based on JSON.stringify(value[, replacer[, space]]).
Starred by 160 users
Forked by 24 users
Languages JavaScript 98.2% | TypeScript 1.6% | JavaScript 98.2% | TypeScript 1.6%
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 › 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
YouTube
youtube.com › watch
How to Pretty Print JSON | React Tutorial - YouTube
How to Pretty Print JSONFree crash courses:React JWT Authentication: https://youtu.be/T5dIjye4b-IReact Redux: https://youtu.be/RPFr-hiFiU0React Redux Saga: h...
Published July 29, 2023
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/
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%
GitHub
github.com › fis-components › react-json-pretty
GitHub - fis-components/react-json-pretty: Fork from https://github.com/chenckang/react-json-pretty.git
This is a react component that help you to prettify your json strings on the browser based on JavaScript.
Author fis-components
YouTube
youtube.com › watch
How to Render JSON in React | Custom Pretty-Print Component Tutorial - YouTube
🚀 Learn how to render JSON data CLEANLY in React using a custom component! In this tutorial, I’ll walk you through building a reusable PrintJson component t...
Published May 20, 2025
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
import React, { Component } from 'react'; import PrettyJson from '@loopmode/react-pretty-json'; export class App extends Component { state = { foo: "foo", bar: "bar", nested: { stuff: "we needed a nested value", some: Immutable.fromJS({ data: 'immutable as well!'
Author loopmode
CopyProgramming
copyprogramming.com › howto › how-do-i-display-prettyprinted-json-in-a-react-component
How to Display Pretty-Printed JSON in React Components: Complete Guide for 2026
December 27, 2025 - React provides both built-in JavaScript ... and most straightforward method to display pretty-printed JSON in React is using the native JavaScript JSON.stringify() method combined with the HTML <pre> tag....
Techboxweb
techboxweb.com › how-to-pretty-print-json-in-react
How to pretty print JSON in react? - TechBoxWeb
September 5, 2020 - Next Js is a very powerful react framework that lets you render React on the server side. Next Js comes with a lot… · September 5, 2020Comments Off on How to pretty print JSON in react?
Top answer 1 of 7
374
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:
Copyvar 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
Copyclass 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
Copyconst PrettyPrintJson = ({data}) => {
// (destructured) data could be a prop for example
return (<div><pre>{ JSON.stringify(data, null, 2) }</pre></div>);
}
Or, ...
Copyconst 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+)
Copyconst 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
Copy<pre>{JSON.stringify(data, null, 2)}</pre>