react-querybuilder vs react-jsonschema-form
React Form Libraries Comparison
1 Year
react-querybuilderreact-jsonschema-formSimilar Packages:
What's React Form Libraries?

React form libraries help developers create and manage forms in React applications efficiently. They provide tools for handling form state, validation, and submission, allowing developers to focus on building user interfaces without worrying about the underlying form mechanics. These libraries streamline the process of creating complex forms with dynamic validation and data handling, making them essential for modern web applications that require user input.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-querybuilder77,6091,4857.32 MB2312 days agoMIT
react-jsonschema-form35,81714,854-2935 years agoApache-2.0
Feature Comparison: react-querybuilder vs react-jsonschema-form

Form Generation

  • react-querybuilder:

    react-querybuilder does not generate forms in the traditional sense but provides a UI for users to build queries. It allows users to select fields, operators, and values, creating a custom query structure that can be submitted to a backend service.

  • react-jsonschema-form:

    react-jsonschema-form automatically generates forms based on JSON Schema definitions. This feature allows developers to create forms without manually defining each input field, making it easier to maintain and update forms as the data model changes.

Validation

  • react-querybuilder:

    react-querybuilder focuses on query construction rather than form validation. However, it allows developers to implement custom validation logic for the queries built by users, ensuring that the generated queries are syntactically correct and adhere to the expected format.

  • react-jsonschema-form:

    react-jsonschema-form supports built-in validation based on JSON Schema. Developers can define validation rules directly in the schema, ensuring that user input is validated before submission, which helps maintain data integrity.

Customization

  • react-querybuilder:

    react-querybuilder is highly customizable in terms of the query structure and the UI components used for building queries. Developers can define their own operators and field types, allowing for a flexible query-building experience that can adapt to various data sources.

  • react-jsonschema-form:

    react-jsonschema-form offers a high degree of customization through the use of custom widgets and fields. Developers can create their own input components to match the design and functionality requirements of their applications, providing a tailored user experience.

User Experience

  • react-querybuilder:

    react-querybuilder enhances user experience by providing an intuitive interface for constructing queries. Users can visually build their queries using drag-and-drop functionality, making it accessible even for those without technical expertise.

  • react-jsonschema-form:

    react-jsonschema-form provides a straightforward user experience by automatically generating forms that are easy to navigate. It handles complex form layouts and validation messages, ensuring users receive immediate feedback on their input.

Integration

  • react-querybuilder:

    react-querybuilder can be integrated with various data sources and backend services, allowing developers to execute the constructed queries against APIs or databases. This integration capability makes it versatile for applications that need to filter or search data.

  • react-jsonschema-form:

    react-jsonschema-form integrates seamlessly with various state management libraries and can be easily connected to APIs for data submission. This makes it a suitable choice for applications that require dynamic form handling and data persistence.

How to Choose: react-querybuilder vs react-jsonschema-form
  • react-querybuilder:

    Choose react-querybuilder if your application requires users to build complex queries through a user-friendly interface. It is ideal for applications that involve filtering or searching datasets where users need to specify multiple conditions and logical operators.

  • react-jsonschema-form:

    Choose react-jsonschema-form if you need to generate forms dynamically based on JSON Schema definitions. It is particularly useful for applications that require a flexible form structure and validation rules that can change based on user input or data models.

README for react-querybuilder

react-querybuilder

The Query Builder component for React

React Query Builder is a fully customizable query builder component for React, along with a collection of utility functions for importing from, and exporting to, various query languages like SQL, MongoDB, and more.

Screenshot

Basic usage

npm i react-querybuilder
# OR yarn add / pnpm add / bun add
import { useState } from 'react';
import { Field, QueryBuilder, RuleGroupType } from 'react-querybuilder';
import 'react-querybuilder/dist/query-builder.css';

const fields: Field[] = [
  { name: 'firstName', label: 'First Name' },
  { name: 'lastName', label: 'Last Name' },
  { name: 'age', label: 'Age', inputType: 'number' },
  { name: 'address', label: 'Address' },
  { name: 'phone', label: 'Phone' },
  { name: 'email', label: 'Email', validator: ({ value }) => /^[^@]+@[^@]+/.test(value) },
  { name: 'twitter', label: 'Twitter' },
  { name: 'isDev', label: 'Is a Developer?', valueEditorType: 'checkbox', defaultValue: false },
];

const initialQuery: RuleGroupType = {
  combinator: 'and',
  rules: [],
};

export const App = () => {
  const [query, setQuery] = useState(initialQuery);

  return <QueryBuilder fields={fields} defaultQuery={query} onQueryChange={setQuery} />;
};

Customizations are not limited to the following libraries, but these have first-class support through their respective compatibility packages:

| Library | Compatibility package | Demo | Example projects | | -------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | Ant Design | @react-querybuilder/antd | demo | CodeSandbox · StackBlitz | | Bootstrap | @react-querybuilder/bootstrap | demo | CodeSandbox · StackBlitz | | Bulma | @react-querybuilder/bulma | demo | CodeSandbox · StackBlitz | | Chakra UI | @react-querybuilder/chakra | demo | CodeSandbox · StackBlitz | | Fluent UI | @react-querybuilder/fluent | demo | CodeSandbox · StackBlitz | | Mantine | @react-querybuilder/mantine | demo | CodeSandbox · StackBlitz | | MUI | @react-querybuilder/material | demo | CodeSandbox · StackBlitz | | React Native | @react-querybuilder/native | | CodeSandbox · StackBlitz | | Tremor | @react-querybuilder/tremor | demo | CodeSandbox · StackBlitz |

[!TIP]

To enable drag-and-drop, use @react-querybuilder/dnd.

For enhanced date/time support, use @react-querybuilder/datetime.

Export

To export queries as a SQL WHERE clause, MongoDB query object, or one of several other formats, use formatQuery.

const query = {
  combinator: 'and',
  rules: [
    {
      field: 'first_name',
      operator: 'beginsWith',
      value: 'Stev',
    },
    {
      field: 'last_name',
      operator: 'in',
      value: 'Vai, Vaughan',
    },
  ],
};

formatQuery(query, 'sql');
/*
"(first_name like 'Stev%' and last_name in ('Vai', 'Vaughan'))"
*/

Import

To import queries use parseSQL, parseMongoDB, parseJsonLogic, parseJSONata, parseCEL, or parseSpEL depending on the source.

// Tip: `parseSQL` will accept either a full `SELECT` statement or a `WHERE` clause by itself.
// Everything but the `WHERE` expressions will be ignored.

const query = parseSQL(
  `SELECT * FROM my_table WHERE first_name LIKE 'Stev%' AND last_name in ('Vai', 'Vaughan')`
);

console.log(query);
/*
{
  "combinator": "and",
  "rules": [
    {
      "field": "first_name",
      "operator": "beginsWith",
      "value": "Stev",
    },
    {
      "field": "last_name",
      "operator": "in",
      "value": "Vai, Vaughan",
    },
  ],
}
*/

Utilities

formatQuery, transformQuery, and the parse* functions can be used without importing from react (on the server, for example) like this:

import { formatQuery } from 'react-querybuilder/formatQuery';
import { parseCEL } from 'react-querybuilder/parseCEL';
import { parseJSONata } from 'react-querybuilder/parseJSONata';
import { parseJsonLogic } from 'react-querybuilder/parseJsonLogic';
import { parseMongoDB } from 'react-querybuilder/parseMongoDB';
import { parseSpEL } from 'react-querybuilder/parseSpEL';
import { parseSQL } from 'react-querybuilder/parseSQL';
import { transformQuery } from 'react-querybuilder/transformQuery';

(As of version 7, the parse* functions are only available through these extended exports.)