GithubHelp home page GithubHelp logo

tanmancan / react-json-print Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 2.0 200 KB

React component that pretty prints JSON object in a collapsible tree view

Home Page: https://www.npmjs.com/package/react-json-print

License: MIT License

JavaScript 76.38% HTML 2.13% TypeScript 19.96% CSS 1.53%

react-json-print's Introduction

React JSON Print

Pretty prints JSON object in a collapsible tree view. A Vue.js verion is available here

Demo: https://tanmancan.github.io/examples/react-json-print/

example JSON from: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON

Install

npm install react-json-print

Usage

This package provides a react component to be used in your existing app. The component is compiled, targeting es2018, but you may also use the Typescript version.

import ReactJsonPrint from 'react-json-print'

const App = () => <ReactJsonPrint dataObject={{}} />

Use the Typescript version

import ReactJsonPrint from 'react-json-print/src/react-json-print';

const App = () => <ReactJsonPrint dataObject={{}} />

Props

dataObject

type: (string|number|boolean|null|object|array)

default: null

The data to be printed. Can be primitives, objects, or arrays. All values must be valid JSON types and all object keys must be valid JSON type. (ie. string not Symbol);

const myDataObject = {
  one: 1,
  two: 2,
  array: [
    true,
    false,
    'string',
  ],
};

const App = () => <ReactJsonPrint dataObject={myDataObject} />

dataString

type: (string)

default: (undefined)

The data to be printed, provided as a valid JSON string. The string will be parsed via JSON.parse. If both dataString and dataObject are provided, the dataObject value will be used.

const myDataString = '{"one":1, "two":2, "array":[true, false, "string"]}';

const App = () => <ReactJsonPrint dataString={myDataString} />

expanded

type: (boolean)

default: false

Displays the entire tree in an expanded state. By default all nested nodes in the tree are collapsed.

const myDataObject = {
  ...
};

const App = () => <ReactJsonPrint expanded dataObject={myDataObject} />

depth

type: (number)

default: 0

Limits how many levels deep to display child nodes. Value of 0 will print all child nodes. Useful for deeply nested data, when you want to limit the number of node displayed.

const myDataObject = {
  ...
};

const App = () => <ReactJsonPrint depth={2} dataObject={myDataObject} />

© Tanveer Karim

react-json-print's People

Contributors

tanmancan avatar

Stargazers

Mauro avatar Pablo Schaffner avatar Vitalii avatar Daegi Kim avatar  avatar Sait Ergün avatar  avatar

Watchers

James Cloos avatar  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.