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
This is a lightweight and tiny react component that helps you to format and prettify the JSON data.
      » npm install react-json-pretty
    
Published   Oct 14, 2019
Version   2.2.0
Author   chenckang@gmail.com
🌐
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.
🌐
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
🌐
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 › 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% | JavaScript 98.2% | TypeScript 1.6%
🌐
DhiWise
dhiwise.com › post › step-by-step-guide-implementing-react-json-formatter
A Comprehensive Guide to React JSON Formatter
September 5, 2024 - This code snippet assumes that the JSON data is an array of objects with name, age, and location properties. To display JSON data nicely in React, you can use a combination of the JSON.stringify method for formatting and CSS for styling.
Find elsewhere
🌐
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...
🌐
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() { ...
🌐
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-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
🌐
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 - The JSON.stringify commands accepts 3 parameters: the value, the replacer, and the amount of spaces. That means that you can also print the array with some more spacing, with the code below:
🌐
Medium
medium.com › coding-at-dawn › how-to-pretty-print-json-in-just-one-line-of-javascript-html-or-react-2e79edd2b7ee
How To Pretty Print JSON in Just One Line of JavaScript + HTML (or React) | by Dr. Derek Austin 🥳 | Coding at Dawn | Medium
January 6, 2023 - How To Pretty Print JSON in Just One Line of JavaScript + HTML (or React) Ever need to debug a giant JSON object while working on frontend development? I’ve got you covered. When you’re …
🌐
Medium
medium.com › dataseries › react-tips-redux-states-dynamic-elements-and-pretty-print-json-be2358bcbe48
React Tips — Redux States, Dynamic Elements, and Pretty Print JSON | by John Au-Yeung | DataSeries | Medium
July 27, 2020 - React Tips — Redux States, Dynamic Elements, and Pretty Print JSON React is a popular library for creating web apps and mobile apps. In this article, we’ll look at some tips for writing better …
🌐
npm
npmjs.com › package › react-json-prettify
react-json-prettify - npm
More css customization (background-color, background-url, font-weight). Styles of brackets and braces. Inline options for arrays. react · json · pretty · prettify · nice · beautiful · awesome · npm i react-json-prettify · github.com/GuillaumeCisco/react-json-prettify ·
      » npm install react-json-prettify
    
Published   Feb 17, 2020
Version   0.2.0
Author   Guillaume Cisco
🌐
Maxheinritz
maxheinritz.com › posts › react-json-pretty-print.html
React JSON pretty print
"" : ","; if (customValueRenderer) { const renderedValue = customValueRenderer(value); if (renderedValue) { return ( <> {renderedValue} {maybeTrailingComma} </> ); } } return ( <> <JsonPrettyPrintValue value={value} customValueRenderer={customValueRenderer} indent={indent} depth={depth} maxDepth={maxDepth} /> {maybeTrailingComma} </> ); } function JsonPrettyPrintValue({ value, customValueRenderer, indent, depth, maxDepth, }: { value: Record<string, any>; customValueRenderer?: (value: any) => JSX.Element | undefined; indent: number; depth: number; maxDepth: number; }) { if (value === undefined
🌐
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
🌐
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....
🌐
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.