Description
react-json-pretty is a small React component that formats and prettifies JSON data for display in the browser. You pass it a data prop that holds either a JSON string or a plain JavaScript object. It is based on JSON.stringify, so it supports the same optional replacer and spacing parameters. Styling works in two ways: you can import one of its themes through a stylesheet loader such as css-loader in webpack, or use the theme prop, whose values are applied as inline styles on the target elements. You can also set custom styles for a specific value type, such as the padding of the main area or the font size of normal values. To catch parse problems, pass an onJSONPrettyError function, which receives the errors from JSON.parse. The README notes that objects which are not plain should be preprocessed with circular-json or a similar tool before they are passed in.…
Highlights
- Formats and prettifies JSON in a React component
- Accepts a JSON string or a plain object
- Themes through a stylesheet or the theme prop
- Custom styles for each value type
- Error callback for JSON.parse errors
Ratings & Reviews
No ratings yet
Be the first to rate react-json-pretty.
People also visit
react-json-pretty FAQ
What does react-json-pretty do?
It is a lightweight React component that formats and prettifies JSON data for display in the browser.
What data can I pass in?
The data prop takes a JSON string or a plain JavaScript object. If your object is not plain, the README suggests preprocessing it with circular-json or a similar tool.
How do I change the look?
Import a theme through a stylesheet loader such as css-loader in webpack, or use the theme prop, whose values become inline styles. You can also set styles for a specific value type.
How are errors handled?
Pass an onJSONPrettyError function. It receives the errors that JSON.parse throws.
How does it format the output?
It is based on JSON.stringify, so it supports the same replacer and spacing options.
What are the best react-json-pretty alternatives?
Popular alternatives to react-json-pretty include react18-json-view, searchable-react-json-view and @uiw/react-json-view. See all react-json-pretty alternatives















