npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reactjs-json-editor

v0.1.2

Published

A react component which is basically JavaScript Object editor which lets to edit any JSON compatible JavaScript object passed to it.

Downloads

426

Readme

This package contains a JSON Editor component which can be used to edit any JSON compatible JavaScript object from within the browser. Currently this implementation is available only for react projects. This is a simple and tiny react component which is just ~16kb (~4kb gz) package and do not have any external dependency except React.

Live demo:

This component is used in following chrome extension for viewing and editing the objects stored in index db by any websites:

https://chrome.google.com/webstore/detail/dev-assistant-modify-requ/omjocblcimogflgejnnadnmbfmngblmd?utm_source=jec

Installation:

If you have an existing react application, run the following commands to download the JSON Editor component.

npm i reactjs-json-editor@latest --save

Once installed you can import this component along with its styles and you are done.

Sample usage

import React, { PureComponent } from 'react';
import { JSONEditor } from 'reactjs-json-editor';
import 'reactjs-json-editor/css/style.css';

class App extends PureComponent {
    state = {
        objectToEdit: {
            aString: 'Some string',
            aNumber: 123.45,
            aLink: 'https://www.google.com',
            aNull: null,
            anUndefined: undefined,
            object: {
                anArray: [
                    new Date(),
                    { string: 'Some other string' }
                ]
            }
        }
    };

    setValue = (value) => this.setState({ objectToEdit: value });

    render() {
        const { objectToEdit } = this.state;

        return (
            <JSONEditor
                value={objectToEdit}
                onChange={this.setValue}
            />
        );
    }
}

export default App;

Sample Output

alt

Features:

  • Supports viewing JS Object / JSON in tree format.
  • Supports editing datatypes like String, Number, DateTime, Object, Array, null & undefined.
  • Supports expanding and collapsing of Array and Objects
  • Can automatically identify what type of data is being entered by the user and automatically convert the data to appropriate datatype.
  • Support editing any property name or values of both objects and array's.
  • Support inserting of new item or removing an existing item from an array.
  • Support adding a new property or remove an existing property from an object.
  • Identify the url stored as value and highlight it for visual difference.
  • Easily customize colors, styles, size and icons by just overriding the css.

Usage:

This component can be used in your page where you would like the JSON Editor to be rendered to the end user. This component would expect the JavaScript object to be passed as value. Raw JSON is not accepted and instad would be considered as a string. If you currently have the JSON string, then use JSON.parse() function to parse the JSON and then pass the resulting object to this component.

| Params | Type | Default | Usage | Description | | ------ | ---- | ------------- | ----- | ----------- | | value | any | - | required | The Javascript object to be edited. This can be any object which is JSON compatible | | args | any | - | optional | This is just an identifier which can be useful when you want to use multiple instance of this component and when change even occur, this would be passed as 2nd argument to your callback function using which you can determine which instance is modified | | onChange | function | - | required | A callback function which would be called everytime the object is edited by the user. The callback's first argument would be the modified object and second argument is the same value passed to args props. If a function is not passed to this prop, then edit functionality would be disabled and the object passed would be readonly. | | allowEditKey | bool | true | optional | This would let you to disable editing of the object property key | | allowEditValue | bool | true | optional | This would let you to disable editing of the object property value | | allowRemove | bool | true | optional | This would let you control if the user is allowed to remove the existing properties or not. | | allowInsert | bool | true | optional | This would let you control if the user is allowed to create a new property or not. | | **isValidName | function | - | optional | This callback would help to validate if the user had provided a valid key name. This function would receive two params (i.e. name and path). Should return a boolean value indicating if the name is accepted or can return a modified name to set the new name | | **parseValue | function | - | optional | This callback would be called with the data the user has provided. You can parse the data and return appropriate object back. If this callback is used then datatype will not be auto detected. Instead, the value returned will be set. |

** Marked properties are not yet available for usage in the current version and is planned for implementation in upcomming versions. For prioritizing the mentioned features or to suggest a new feature please raise a ticket in GitHub repository.

Inspiration

Styles are inspired from JSON Viewer component available for Angular: https://www.npmjs.com/package/jsonformatter