All Projects β†’ TechniqueSoftware β†’ React Json Schema

TechniqueSoftware / React Json Schema

Licence: apache-2.0
Configure and build views using JSON schemas mapped to React components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Json Schema

React Formik Ui
A simple component library, composed out of pure HTML form elements to make your live easier composing forms with Formik and React
Stars: ✭ 154 (+17.56%)
Mutual labels:  react-components, javascript-library
Stardust
🎨Tiller Design System
Stars: ✭ 19 (-85.5%)
Mutual labels:  react-components, javascript-library
React Border Wrapper
A wrapper for placing elements along div borders.
Stars: ✭ 147 (+12.21%)
Mutual labels:  react-components, javascript-library
react-circle-flags
πŸš€ A React component with a collection of 300+ minimal circular SVG country flags. Wrapper of HatScripts/circle-flags
Stars: ✭ 29 (-77.86%)
Mutual labels:  react-components, javascript-library
Json Schema Ref Parser
Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
Stars: ✭ 532 (+306.11%)
Mutual labels:  json-schema, parser
Plantuml Parser
Parse PlantUML with JavaScript or TypeScript
Stars: ✭ 67 (-48.85%)
Mutual labels:  parser, javascript-library
Semantic Ui React
The official Semantic-UI-React integration
Stars: ✭ 12,561 (+9488.55%)
Mutual labels:  react-components, javascript-library
Length.js
πŸ“ JavaScript library for length units conversion.
Stars: ✭ 292 (+122.9%)
Mutual labels:  parser, javascript-library
Swagger Cli
Swagger 2.0 and OpenAPI 3.0 command-line tool
Stars: ✭ 321 (+145.04%)
Mutual labels:  json-schema, parser
Swagger Parser
Swagger 2.0 and OpenAPI 3.0 parser/validator
Stars: ✭ 710 (+441.98%)
Mutual labels:  json-schema, parser
React Rainbow
🌈 React Rainbow Components. Build your web application in a snap.
Stars: ✭ 1,662 (+1168.7%)
Mutual labels:  react-components, javascript-library
Php Zephir Parser
The Zephir Parser delivered as a C extension for the PHP language.
Stars: ✭ 129 (-1.53%)
Mutual labels:  parser
Naivebayes
πŸ“Š Naive Bayes classifier for JavaScript
Stars: ✭ 127 (-3.05%)
Mutual labels:  javascript-library
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-3.05%)
Mutual labels:  parser
React
Modern and minimalist React UI library.
Stars: ✭ 2,546 (+1843.51%)
Mutual labels:  react-components
React Trumbowyg
React wrapper for lightweight WYSIWYG editor Trumbowyg
Stars: ✭ 130 (-0.76%)
Mutual labels:  react-components
Devextreme Reactive
Business React components for Bootstrap and Material-UI
Stars: ✭ 1,800 (+1274.05%)
Mutual labels:  react-components
Rxjs Diagrams
React Components for visualising RxJS observables and operators
Stars: ✭ 126 (-3.82%)
Mutual labels:  react-components
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (-3.82%)
Mutual labels:  parser
Gofeed
Parse RSS, Atom and JSON feeds in Go
Stars: ✭ 1,762 (+1245.04%)
Mutual labels:  parser

react-json-schema

npm install react-json-schema

Construct React elements from JSON by mapping JSON definitions to React components. Use react-json-schema for data-driven layouts, or as an abstraction layer for React components and props.

Render anywhere (as long as it's DOM)! Since react-json-schema does not perform any rendering, the method in which you want to render is up to you. For example, you can use ReactDOMServer.render, ReactDOM.renderToString, etc. if you'd like. This also means JSX is not a dependency for react-json-schema.

Quick Documentation and Examples

Full Documentation

Schema

The primary resource needed is a defined schema in JSON or a JavaScript object literal. It's recommended that schema attributes mainly define React component props. The parser explicitly handles the following attributes:

  • component: MUST exist and be defined by a string or React component (must be a string if describing a native HTML tag)
  • children: MAY exist to define sub-components
  • text: MAY exist to as a string to define inner HTML text (overrides children)
  • key: MAY exist to define a key for dynamic children

Example JSON schema

const schema = {
  "component": "CommentList",
  "children": [
    {
      "component": "Comment",
      "author": "Pete Hunt",
      "children": "This is one comment"
    },
    {
      "component": "Comment",
      "author": "Jordan Walke",
      "children": "This is *another* comment"
    },
    {
      "component": "a",
      "href": "#help",
      "text": "I need help"
    }
  ]
};

Example JS literal

...
  {
    "component": Comment,
    "author": "Pete Hunt",
    "children": "This is one comment"
  },
...
Dynamic Children and Keys

When arrays of components exist (like children), react-json-schema will resolve a key for the element, which follows the rules for dynamic children. It will either use a custom key if defined, or resolve a numeric key based on the array index.

Example of defining child keys

...
  {
    "component": "Comment",
    "key": "0ab19f8e", // defined key
    "author": "Pete Hunt",
    "children": "This is one comment"
  },
...

Component Mapping

React components need to be exposed to the react-json-schema so that the parser can create React elements. If the schema contains object literals with component references, the schema is exposing the React components and no additional configuration is needed. If the schema does not contain references to components, the components can be exposed via setComponentMap.

Example for exposing non-exposed components (ES6)

/* es6 object literal shorthand: { ContactForm } == { ContactForm: ContactForm } */
contactForm.setComponentMap({ ContactForm, StringField });

Parsing

Use parseSchema to render React elements. It returns the root node. Note that if your schema's root is an array, you'll have to wrap the schema in an element.

Example (ES6)

ReactDOM.render(contactForm.parseSchema(schema),
  document.getElementById('contact-form'));

Complete Example

import ReactDOM from 'react-dom';
import ReactJsonSchema from 'react-json-schema';

import FormStore from 'FormStore';
import CommentList from 'CommentList';
import Comment from 'Comment';

// For this example, let's pretend I already have data and am ignorant of actions
const schema = FormStore.getFormSchema();
const view = new ReactJsonSchema();

view.setComponentMap({ CommentList, Comment });

ReactDOM.render(view.parseSchema(schema),
  document.getElementById('content'));

Demo an Example Codebase

To run the demo

Contribution and Code of Conduct

If you'd like to ask a question, raise a concern, or contribute, please follow our contribution guidelines.

Alternatives

  • react-jsonschema-form: A React component for building Web forms from JSON Schema. This library further abstracts React components, making it easier to build forms. Also, it comes with components. React-json-schema is a lighter alternative that allows the use of any components.

Roadmap

  • Playground on our public site for discoverability
  • Possibility of react-native-json-schema
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].