Plus · JsonViewer
JsonViewer
Used for displaying and editing JSON data

When to use

The JsonViewer component can be used for the display and editing of JSON data.
Semi mainly referred to the design concept of the text-buffer data structure of VS Code, reused some utilities and data type definitions (Token parsing, language services, etc.), and implemented the JsonViewer component in combination with our functional/style customization requirements. Visually, it will be more coordinated with other components within the Semi Design system, and it will be more convenient for customized rendering and customization of specific data types.
Compared with directly using MonacoEditor, Semi JsonViewer has additional processing in engineering construction, is simpler to use, and there is no need to pay attention to complex configurations such as Webpack plugins and worker loaders. At the same time, since we only focus on the JSON data format, it is more lightweight. While being ready to use out of the box, it has a smaller size (📦-96%), a more extreme loading speed (🚀 -53.5%), and less memory occupation (⬇️71.6% reduction). For data with five million lines and below, data loading and parsing can be completed within 1 second.
Detailed comparison data can be referred to in the Performance section.
  • If you only need to preview/edit JSON and don't need to modify other more complex programming languages, we recommend that you choose JsonViewer.
  • If you also need to handle data/code files in other formats and the full capabilities of a code editor (syntax highlighting, code completion, error prompts, complex editing, etc.) are essential and the build product size is not a key concern, we recommend that you choose Monaco Editor.

Demos

How to import

JsonViewer supported from v2.71.0

Basic Usage

Basic usage of JsonViewer. Pass in the height and width parameters to set the height, width and initial value of the component. Pass in the JSON string through the value.

Differrent lineHeight

Configure the lineHeight parameter of options to set a fixed line height (unit: px, default 18).

Autowrap

Configure the autoWrap parameter of options. When it is set to true, the component will automatically wrap lines according to the length of the content.

Format options

Configure options.formatOptions to set the formatting configuration of the component.
  • tabSize: number,set the indent size to 4, which means each level of indentation is 4 spaces.
  • insertSpaces: boolean,when it is true, it means using spaces for indentation, and when it is false, it means using tabs.
  • eol: string,set the line break character, which can be \n\r\n

API Reference

JsonViewer

AttributeDescriptionTypeDefault
valueDisplay contentstring-
heightHeight of wrapper DOMnumber-
widthWidth of wrapper DOMnumber-
classNameclassName of wrapper DOMstring-
styleInlineStyle of wrapper DOMobject-
showSearchWhether to show search iconbooleantrue
optionsFormatting configurationJsonViewerOptions-
onChangeCallback for content change(value: string) => void-

JsonViewerOptions

AttributeDescriptionTypeDefault
lineHeightHeight of each line of content, unit:pxnumber20
autoWrapWhether to wrap lines automatically.booleantrue
readOnlyWhether to be read-only.booleanfalse
formatOptionsContent format settingFormattingOptions-

FormattingOptions

AttributeDescriptionTypeDefault
tabSizeIndent size. Unit: pxnumber4
insertSpacesWhether to use spaces for indentationbooleantrue
eolLine break characterstring'\n'

Methods

Methods bound to the component instance can be called via ref to achieve certain special interactions.
MethodDescription
getValue()Get current value
format()Format current content

Performance

Bundle Size

Libs NameSizeSize (Gzip)
JsonViewer203.14kb51.23kb
MonacoEditor5102.0 KB1322.7 KB

Time for rendering data of different magnitudes.

For details on the generation method of the test data, please refer to URL
When the data volume exceeds 500,000 lines, ReactMonacoEditor turns off highlighting and other behaviors by default, and the data comparison does not follow the principle of a single variable.
Libs Name1k lines5k lines10 thousand lines100 thousand lines500 thousand lines1 million lines3 million lines
JsonViewer30.42ms30.66ms36.87ms52.73ms111.02ms178.81ms506.25ms
ReactMonacoEditor72.01ms73.76ms76.64ms97.89ms133.31ms202.79ms495.53ms
Performance improvement57.70%58.41%51.87%46.11%---