Giter Site home page Giter Site logo

json-view's Introduction

jsonviewer

showcase

What?

jsonviewer is a blazingly fast component for creating cascade json view, written in solidjs.

Features:

  • fast, using solidjs
  • easy to use
  • lazy rendering, only renders the cascade you opened
  • easy copy, double click on property to copy value
  • full control on styling, using css variables
  • control preview length

Installation

yarn yarn add @frank-tomato/jsonviewer

npm npm install @frank-tomato/jsonviewer

Usage

Solid

import { JsonView } from '@frank-tomato/jsonviewer';

const data = {
  foo: 1,
  bar: 'text',
  arr: [
    'text in array',
    2,
    {}
  ],
  obj:{
    text: 'nested text',
    bool: true,
    null: null
  }
};

const json = JSON.stringify(data);

...

<JsonView json={json} {...props} />

javascript

import { renderJsonView } from '@frank-tomato/jsonviewer';

const data = {
  foo: 1,
  bar: 'text',
  arr: [
    'text in array',
    2,
    {}
  ],
  obj:{
    text: 'nested text',
    bool: true,
    null: null
  }
};

const json = JSON.stringify(data);

renderJsonView(
  document.getElementById('jsonviewer'), 
  { json: json, ...props }
);

Preview

preview image

Props

defaultOpen

type: boolean

Should the component open first cascade when mounted.

default: false

Solid

<JsonView json={json} defaultOpen />

JS

renderJsonView(
  document.getElementById('jsonviewer'), 
  { json: data, defaultOpen: true }
);

showcase

defaultOpen: false

defaultOpen-false

defaultOpen: true

preview image

depthIndicator

type: boolean

Show depth indicator or not.

default: true

Solid

<JsonView json={json} depthIndicator={false} />

JS

renderJsonView(
  document.getElementById('jsonviewer'), 
  { json: data, depthIndicator: false }
);

showcase

depthIndicator: true

depthIndicator-true

depthIndicator: false

depthIndicator-false

maxLength

type: number

Control the length of the preivew text.

default: 100

Solid

<JsonView json={json} maxLength={50} />

JS

renderJsonView(
  document.getElementById('jsonviewer'), 
  { json: data, maxLength: 50 }
);

showcase

maxLength: 100

maxLength-100

maxLength: 50

maxLength-50

Styling

To change the colors, simply overide the css variables of .jsonView__details

Example

Change the marker color to red

.jsonView__container{
  --marker-color: red;
}

All css variables visualized css-variables

css variables default value

  --name-color: rgb(20 133 189);
  --preview-name-color: rgb(163, 163, 163);
  --preview-color: rgb(107, 107, 107);
  --marker-color: rgb(170, 170, 170);
  --marker-open-color: rgb(8, 200, 226);
  --content-string-color: rgb(7, 124, 1);
  --content-boolean-color: rgb(125, 13, 153);
  --content-number-color: rgb(125, 13, 153);
  --content-null-color: rgb(109, 109, 109);
  --left-border-indicator-color: rgb(184, 182, 182);

Font example

Change font

.jsonView__container{
  font-family: ...;
}

json-view's People

Contributors

its-frank-huang avatar zhanghanwen96 avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

zhanghanwen96

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.