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
🌐
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%
🌐
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
npmjs.com › package › react-json-formatter
react-json-formatter - npm
Use the Object jsonStyle to control the style of formatted JSON.
      » 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.
Find elsewhere
🌐
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
🌐
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
🌐
npm Trends
npmtrends.com › react-json-pretty-vs-react-json-view-vs-react-json-viewer
react-json-pretty vs react-json-view vs react-json-viewer | npm trends
Comparing trends for react-json-pretty 2.2.0 which has 123,479 weekly downloads and 160 GitHub stars vs. react-json-view 1.21.3 which has 999,754 weekly downloads and 3,664 GitHub stars vs. react-json-viewer 3.0.1 which has 2,640 weekly downloads and 153 GitHub stars.
🌐
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 › 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. Presently, it provides a monikai theme style for you, and of course you are free to add your own theme if you like for this is pretty easy. ...
Author   fis-components
🌐
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.