Convert Figma logo to code with AI

rjsf-team logoreact-jsonschema-form

A React component for building Web forms from JSON Schema.

14,093
2,175
14,093
284

Top Related Projects

A React component for building Web forms from JSON Schema.

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.

Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.

A React library for building forms from any schema.

Quick Overview

React JSON Schema Form (rjsf) is a powerful library for building HTML forms in React based on JSON Schema. It automatically generates form fields and handles validation based on the provided schema, making it easier to create complex forms with minimal code.

Pros

  • Automatic form generation from JSON Schema
  • Built-in validation and error handling
  • Highly customizable with themes and custom widgets
  • Supports complex form structures and nested objects

Cons

  • Learning curve for complex schemas and customizations
  • Performance can be an issue with very large forms
  • Limited built-in styling options (requires additional theming)
  • Some edge cases in JSON Schema may not be fully supported

Code Examples

  1. Basic form generation:
import Form from "@rjsf/core";

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "number" }
  }
};

const MyForm = () => <Form schema={schema} />;
  1. Custom validation:
const validate = (formData, errors) => {
  if (formData.age < 18) {
    errors.age.addError("Must be at least 18 years old");
  }
  return errors;
};

const MyForm = () => <Form schema={schema} validate={validate} />;
  1. Custom widget:
const CustomInput = (props) => (
  <input
    type="text"
    className="custom-input"
    value={props.value}
    onChange={(event) => props.onChange(event.target.value)}
  />
);

const uiSchema = {
  name: { "ui:widget": CustomInput }
};

const MyForm = () => <Form schema={schema} uiSchema={uiSchema} />;

Getting Started

  1. Install the package:

    npm install @rjsf/core @rjsf/utils
    
  2. Create a basic form:

    import React from "react";
    import Form from "@rjsf/core";
    
    const schema = {
      type: "object",
      properties: {
        name: { type: "string", title: "Name" },
        email: { type: "string", format: "email", title: "Email" }
      },
      required: ["name", "email"]
    };
    
    const MyForm = () => (
      <Form
        schema={schema}
        onSubmit={({ formData }) => console.log(formData)}
      />
    );
    
    export default MyForm;
    
  3. Render the form in your React application.

Competitor Comparisons

A React component for building Web forms from JSON Schema.

Pros of react-jsonschema-form

  • Identical functionality and features as both repositories are the same project
  • Consistent documentation and community support
  • Regular updates and maintenance

Cons of react-jsonschema-form

  • No unique advantages over the other repository
  • Potential confusion for users due to duplicate repositories
  • Possible split in community contributions and issue tracking

Code Comparison

Both repositories contain identical code, as they are the same project. Here's a sample from both:

import React from "react";
import Form from "@rjsf/core";

const schema = {
  title: "Todo",
  type: "object",
  required: ["title"],
  properties: {
    title: {type: "string", title: "Title", default: "A new task"},
    done: {type: "boolean", title: "Done?", default: false}
  }
};

const MyForm = () => (
  <Form schema={schema} />
);

This code snippet is identical in both repositories, demonstrating that they are the same project. The repositories appear to be duplicates, which may lead to confusion among users and contributors. It's recommended to use the official repository maintained by the rjsf-team for the most up-to-date version and community support.

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.

Pros of jsonform

  • Lightweight and simple to use
  • Supports a wider range of browsers, including older ones
  • Can be used with or without jQuery

Cons of jsonform

  • Less actively maintained (last commit was in 2017)
  • Fewer advanced features and customization options
  • Limited documentation and community support

Code Comparison

jsonform:

$('form').jsonForm({
  schema: {
    name: { type: 'string', title: 'Name', required: true },
    age: { type: 'number', title: 'Age' }
  }
});

react-jsonschema-form:

import Form from "@rjsf/core";

const schema = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    age: { type: "number", title: "Age" }
  },
  required: ["name"]
};

<Form schema={schema} />

Both libraries allow you to create forms based on JSON schemas, but react-jsonschema-form uses a more modern React-based approach, while jsonform relies on jQuery. react-jsonschema-form offers more advanced features, better documentation, and active maintenance, making it a preferred choice for most modern web applications. However, jsonform might be suitable for simpler projects or those requiring support for older browsers.

Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.

Pros of JSONForms

  • Framework-agnostic, supporting React, Angular, and Vue
  • More flexible and customizable rendering engine
  • Better support for complex, nested data structures

Cons of JSONForms

  • Steeper learning curve due to increased complexity
  • Smaller community and fewer resources compared to react-jsonschema-form
  • Less extensive documentation and examples

Code Comparison

react-jsonschema-form:

import Form from "@rjsf/core";

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "number" }
  }
};

<Form schema={schema} />

JSONForms:

import { JsonForms } from '@jsonforms/react';

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "integer" }
  }
};

<JsonForms
  schema={schema}
  data={{}}
  renderers={renderers}
  cells={cells}
/>

Both libraries use JSON Schema for form definition, but JSONForms requires additional configuration for renderers and cells, offering more customization options at the cost of increased complexity.

A React library for building forms from any schema.

Pros of Uniforms

  • More flexible schema support, including SimpleSchema and GraphQL
  • Better TypeScript integration and type safety
  • Easier customization of form components and layouts

Cons of Uniforms

  • Smaller community and fewer resources compared to react-jsonschema-form
  • Steeper learning curve for beginners
  • Less comprehensive documentation

Code Comparison

react-jsonschema-form:

import Form from "@rjsf/core";

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "number" }
  }
};

<Form schema={schema} onSubmit={onSubmit} />

Uniforms:

import { AutoForm } from 'uniforms-semantic';
import SimpleSchema from 'simpl-schema';

const schema = new SimpleSchema({
  name: String,
  age: Number
});

<AutoForm schema={schema} onSubmit={onSubmit} />

Both libraries aim to simplify form creation based on schemas, but Uniforms offers more flexibility in schema types and better TypeScript support. react-jsonschema-form has a larger community and more extensive documentation, making it easier for beginners to get started. The code comparison shows that Uniforms uses a different approach to schema definition, which can be more concise in some cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status Contributors Apache 2.0 License

Logo

react-jsonschema-form

A simple React component capable of using JSON Schema to declaratively build and customize web forms.
Explore the docs »

View Playground · Report Bug · Request Feature

playground animation

Supported Themes

Documentation

Read our documentation, powered by Docusaurus.

Live Playground

A live playground is hosted on GitHub Pages.

Contributing

Read our contributors' guide to get started.

Credits

Testing powered by BrowserStack

NPM DownloadsLast 30 Days