Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-json-view-lite

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-json-view-lite

JSON viewer component for React focused on performance for large volume input while still providing few customiziation features

  • 0.9.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
251K
decreased by-15.45%
Maintainers
1
Weekly downloads
 
Created
Source
npm no dependencies size build coverage tree-shakeable types included downloads per month
react-json-view-lite is a tiny component for React allowing to render JSON as a tree. It focused on the balance between performance for large JSON inputs and functionality. It might not have all the rich features (suce as customization, copy, json editinng) but still provides more than just rendering json with highlighting - e.g. ability to collapse/expand nested objects and override css. It is written in TypeScript and has no dependencies.

Install

npm install --save react-json-view-lite

Usage

import * as React from 'react';

import { JsonView, darkStyles, defaultStyles } from 'react-json-view-lite';
import 'react-json-view-lite/dist/index.css';

const json = {
  a: 1,
  b: 'example'
};

const App = () => {
  return (
    <React.Fragment>
      <JsonView data={json} shouldInitiallyExpand={(level) => true} style={defaultStyles} />
      <JsonView data={json} shouldInitiallyExpand={(level) => true} style={darkStyles} />
    </React.Fragment>
  );
};

export default App;

Demo

https://codesandbox.io/s/react-json-view-lite-example-wvdjl

(thanks to @idindrakusuma)

Props

NameTypeDefault ValueDescription
dataObject | Array<any>Data which should be rendered
styleStylePropsdefaultStylesOptional. CSS classes for rendering. Library provides two build-in implementations: darkStyles, defaultStyles (see below)
shouldInitiallyExpand(level: number, value: any, field?: string) => booleanallExpandedOptional. Function which will be initially called for each Object and Array of the data in order to calculate should if this node be expanded. level startes from 0, field does not have a value for the array element. Library provides two build-in implementations: allExpanded and collapseAllNested (see below)

Extra exported

NameTypeDescription
defaultStylesStylePropsDefault styles for light background
darkStylesStylePropsDefault styles for dark background
allExpanded() => booleanAlways returns true
collapseAllNested(level: number) => booleanReturns true only for the first level (level=0)

StyleProps

NameTypeDescription
containerstringCSS class name for rendering parent block
basicChildStylestringCSS class name for property block containing property name and value
expanderstringCSS class name for rendering button expanding/collapsing Object and Array nodes
labelstringCSS class name for rendering property names
nullValuestringCSS class name for rendering null values
undefinedValuestringCSS class name for rendering undefined values
numberValuestringCSS class name for rendering numeric values
stringValuestringCSS class name for rendering string values
booleanValuestringCSS class name for rendering boolean values
otherValuestringCSS class name for rendering all other values except Object, Arrray, null, undefined, numeric, boolean and string
punctuationstringCSS class name for rendering ,, [, ], {, }, ...
pointerstringextra CSS class name for parts which are used for expanding/collapsing: , and ...

Comparison with other libraries

Size and dependencies

Here is the size benchmark (using bundlephobia.com) against similar React libraries (found by https://www.npmjs.com/search?q=react%20json&ranking=popularity):

LibraryBundle sizeBundle size (gzip)Dependencies
react-json-view-lite
react-json-pretty
react-json-inspector
react-json-tree
react-json-view
react-json-tree-viewer

Performance

Performance was mesaures using the react-component-benchmark library. Every component was rendered 50 times using the 300Kb json file as data source. All numbers are in milliseconds. Tests were performed on Macbook Air M1 16Gb RAM usging Chrome v96.0.4664.110(official build, arm64). Every component was tested 2 times but there was no significant differences in the results.

LibraryMinMaxAverageMedianP90
react-json-view-lite8160419582582
react-json-pretty2259322456
react-json-inspector6821 109758711905
react-json-tree5651 217658620741
react-json-view1 4031 72215291 5401 631
react-json-tree-viewer266663320278455

As you can see react-json-pretty renders faster than other libraries but it does not have ability to collapse/expand nested objects so it might be good choice if you need just json syntax highlighting.

License

MIT © AnyRoad

FAQs

Package last updated on 02 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc