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
🌐
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'; 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
🌐
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.
Starred by 160 users
Forked by 24 users
Languages   JavaScript 98.2% | TypeScript 1.6%
🌐
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...
🌐
NGCC in Angular Ivy
iq.js.org › questions › react › how-to-pretty-print-json-with-react
How to pretty print JSON with React?
October 28, 2022 - To pretty print JSON with React, you can use the JSON.stringify() method and pass JSON object as the first argument, null as the second argument, and the 2 as the third argument.
🌐
DEV Community
dev.to › gauravadhikari1997 › show-json-as-pretty-print-with-syntax-highlighting-3jpm
Show JSON As Pretty Print With Syntax Highlighting in React - DEV Community
June 24, 2025 - Now we can use our syntaxHighlight function, just pass it with JSON to prettify and highlight ... import { useEffect, useState } from "react"; import { syntaxHighlight } from "./utils"; import "./styles.css"; export default function App() { ...
Find elsewhere
🌐
DhiWise
dhiwise.com › post › step-by-step-guide-implementing-react-json-formatter
A Comprehensive Guide to React JSON Formatter
September 5, 2024 - To beautify JSON data in a React component, you can use the JSON.stringify method with its second argument set to null for the replacer function, and the third argument used to define the number of spaces in the string representation of the JSON data...
🌐
npm
npmjs.com › package › react-json-formatter
react-json-formatter - npm
import React from 'react' import JsonFormatter from 'react-json-formatter' const App = () => { const sample = `{ "string":"ABCDE", "number":1, "null":null, "boolean":true, "object":{ "string":"ABCDE", "number":1, "null":null, "boolean":true }, "array":[ 1, 2, 3, 4, { "string":"ABCDE", "number":1, "null":null, "boolean":true, "array":[ 1, 2, 3, 4, { "string":"ABCDE", "number":1, "null":null, "boolean":true } ] } ] } ` const jsonStyle = { propertyStyle: { color: 'red' }, stringStyle: { color: 'green' }, numberStyle: { color: 'darkorange' } } return <JsonFormatter json={sample} tabWith={4} jsonStyle={jsonStyle} /> } export default App
      » 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
Simple and Lightweight React Component for displaying Json. 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 ...
      » npm install react-json-prettify
    
Published   Feb 17, 2020
Version   0.2.0
Author   Guillaume Cisco
🌐
GitHub
github.com › tanmancan › react-json-print
GitHub - tanmancan/react-json-print: React component that pretty prints JSON object in a collapsible tree view
React component that pretty prints JSON object in a collapsible tree view - tanmancan/react-json-print
Starred by 7 users
Forked by 2 users
Languages   JavaScript 76.4% | TypeScript 20.0% | HTML 2.1% | CSS 1.5%
🌐
C# Corner
c-sharpcorner.com › article › how-to-pretty-print-json-with-reactjs
How to Pretty Print JSON with ReactJS
May 24, 2024 - For this example, we will use a functional component. The JSON.stringify function can be used to convert a JavaScript object into a JSON string. To pretty-print, you pass additional arguments for spacing.
🌐
Techboxweb
techboxweb.com › how-to-pretty-print-json-in-react
How to pretty print JSON in react? - TechBoxWeb
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?
🌐
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/
A react component that pretty-prints JSON data, based on http://jsfiddle.net/unlsj/ - loopmode/react-pretty-json
Author   loopmode
🌐
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
🌐
Marinus Klasen
mklasen.com › home › blog › general › dump / pretty print a json object in react
Dump / pretty print a JSON object in React - Marinus Klasen
July 28, 2022 - To quickly debug something, or temporarily show the data object during development, just to know what you’re working with, it comes in handy to print the full JSON object. Not as a string that’s almost impossible to read, but as a well formatted array. We’ve got a neat little one-liner for that, which I’ll share […]
🌐
Maxheinritz
maxheinritz.com › posts › react-json-pretty-print.html
React JSON pretty print
import React from "react"; function SimpleJsonPrettyPrint(props) { const { jsonObject } = props; return <pre>{JSON.stringify(jsonObject, undefined, 2)}</pre>; }
🌐
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.