Giter Site home page Giter Site logo

json-viewer's Introduction

@textea/json-viewer

npm npm npm codecov Netlify Status

This is a React component for JSON viewer, but not only a JSON viewer.

Json Viewer? ANY Data Viewer โœ…

This is v2 branch with fancy features like 100% TypeScript, lightly code and customizable component support.

If you are looking for v1 version based on mac-s-g/react-json-view, Please see v1.x.

Open in StackBlitz

Usage

NPM

npm install @textea/json-viewer

Yarn

yarn add @textea/json-viewer

PNPM

pnpm add @textea/json-viewer

Type Declaration

see src/type.ts

Basic Example

import { JsonViewer } from '@textea/json-viewer'

const object = { /* my json object */ }
const Component = () => (<JsonViewer value={object}/>)

Customizable data type

import { JsonViewer, createDataType } from '@textea/json-viewer'

const object = {
  // what if I want to inspect a image?
  image: 'https://i.imgur.com/1bX5QH6.jpg',
  // ... other values
}
const Component = () => (
  <JsonViewer
    value={object}
    // just define it
    valueTypes={[
      {
        is: (value) => typeof value === 'string' && value.startsWith('https://i.imgur.com'),
        Component: (props) => <Image height={50} width={50} src={props.value} alt={props.value}/>,
      },
      // or
      createDataType(
        (value) => typeof value === 'string' && value.startsWith('https://i.imgur.com'),
        (props) => <Image height={50} width={50} src={props.value} alt={props.value}/>,
      )
    ]}
  />
)

Avatar Preview

see the full code

Base 16 Theme Support

export const ocean: NamedColorspace = {
  scheme: 'Ocean',
  author: 'Chris Kempson (http://chriskempson.com)',
  base00: '#2b303b',
  base01: '#343d46',
  base02: '#4f5b66',
  base03: '#65737e',
  base04: '#a7adba',
  base05: '#c0c5ce',
  base06: '#dfe1e8',
  base07: '#eff1f5',
  base08: '#bf616a',
  base09: '#d08770',
  base0A: '#ebcb8b',
  base0B: '#a3be8c',
  base0C: '#96b5b4',
  base0D: '#8fa1b3',
  base0E: '#b48ead',
  base0F: '#ab7967'
}

const Component = () => (
  <JsonViewer
    value={object}
    theme={ocean}
  />
)

Ocean Theme Preview

Browser

<!DOCTYPE html>
<html lang="en">
<body>
<div id="json-viewer"></div>
<script src="https://cdn.jsdelivr.net/npm/@textea/json-viewer"></script>
<script>
  new JsonViewer({
    value: { /* ... */ }
  }).render()
</script>
</body>
</html>

Features

  • 100% TypeScript
  • Customizable
    • keyRenderer for customize key renderer
    • valueTypes for customize any value types you want
    • light | dark | base16 Theme support
    • custom metadata
  • Support Next.js SSR
  • onChange props allow users to edit value
  • Inspect object, Array, primitive type, even Map and Set by default.
  • Metadata preview, like total items, length of string...
  • Copy to Clipboard on Click
  • Editor for basic types
  • Fully Test Coverage

Contributors

Acknowledge

This package is originally based on mac-s-g/react-json-view.

Also thanks open source projects that make this possible.

Sponsoring services

Netlify

Netlify lets us distribute the site.

LICENSE

This project is licensed under the terms of the MIT license.

json-viewer's People

Contributors

himself65 avatar github-actions[bot] avatar pionxzh avatar dependabot[bot] avatar xepozz avatar rtritto avatar yazawazi avatar baartch avatar fundon avatar forrestbao avatar banner-keith avatar mfklauberg avatar saul-mirone avatar sukkaw avatar tsmota avatar kahosan avatar samhuk avatar

Watchers

 avatar

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.