focusreactive

payload plugin json form builder

by focusreactive
payload-plugins
Custom fields
v3
^3.90.0
MIT

Overview

Summary generated from the README

Turns a json field into real Payload admin components that editors fill in, while the form shape is built in a drawer inside the admin. The site reads the stored value as a plain object of keys, and new sections need no migration. It requires Payload 3.90 or later and the companion guard plugin, with access rules written in an access policy file.

Features

  • jsonField() renders a json value as text, number, date, select, checkbox, upload, rich text, list, group and tabs
  • In-admin builder to add, rename, reorder and nest fields without a deploy
  • Server-enforced build capability; other editors can only fill in values
  • Optional library of reusable sections shared across json fields
  • Rich text stored and returned as sanitized HTML
  • Upload values resolved only when the reader may read the file

Use cases

  • Let editors define flexible page sections without code changes or migrations
  • Share reusable sections across many pages from a central library
  • Restrict who can change form structure while editors only fill in values

From the author

Edit a Payload JSON field as real admin fields. The shape lives in the value, is built in a drawer, and the site reads plain values by key

Installation

npm i @focus-reactive/payload-plugin-json-form-builder

37

Stars

5

Forks

33

Open Issues

Today

Last Updated

36

Weekly Downloads

v2.0.1

npm Version

463.8 KB

Unpacked Size

2

Dependencies

Repository stars

37+22 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 202637
Dec 4, 202637
Dec 3, 202637
Dec 2, 202637
Dec 1, 202636
Nov 30, 202635
Nov 29, 202635
Nov 28, 202634
Nov 27, 202634
Nov 26, 202634
Nov 25, 202634
Nov 24, 202634
Nov 23, 202634
Nov 22, 202634
Nov 21, 202634
Nov 20, 202633
Nov 19, 202632
Nov 18, 202632
Nov 17, 202632
Nov 16, 202632
Nov 15, 202632
Nov 14, 202632
Nov 13, 202632
Nov 12, 202632
Nov 11, 202632
Nov 10, 202632
Nov 9, 202631
Nov 8, 202631
Nov 7, 202631
Nov 6, 202631
Nov 5, 202631
Nov 4, 202630
Nov 3, 202630
Nov 2, 202630
Nov 1, 202630
Oct 31, 202630
Oct 30, 202630
Oct 29, 202630
Oct 28, 202630
Oct 27, 202630
Oct 26, 202630
Oct 25, 202630
Oct 24, 202629
Oct 23, 202629
Oct 22, 202629
Oct 21, 202629
Oct 20, 202629
Oct 19, 202629
Oct 18, 202629
Oct 17, 202627
Oct 16, 202626
Oct 15, 202626
Oct 14, 202626
Oct 13, 202625
Oct 12, 202625
Oct 11, 202625
Oct 10, 202625
Oct 9, 202625
Oct 8, 202625
Oct 7, 202625
Oct 6, 202624
Oct 5, 202624
Oct 4, 202624
Oct 3, 202623
Oct 2, 202622
Oct 1, 202622
Sep 30, 202620
Sep 29, 202620
Sep 28, 202620
Sep 27, 202620
Sep 26, 202619
Sep 25, 202618
Sep 24, 202618
Sep 23, 202618
Sep 22, 202618
Sep 21, 202618
Sep 20, 202618
Sep 19, 202618
Sep 18, 202618
Sep 17, 202618
Sep 16, 202618
Sep 15, 202618
Sep 14, 202618
Sep 13, 202617
Sep 12, 202617
Sep 11, 202617
Sep 10, 202616
Sep 9, 202616
Sep 8, 202616
Sep 7, 202615
Sep 6, 202615

Shared by 15 plugins in focusreactive/payload-plugins.

npm weekly downloads

39−1.2K since Oct 8

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202639
Dec 4, 202638
Dec 3, 202643
Dec 2, 202648
Dec 1, 202632
Nov 30, 202633
Nov 29, 202632
Nov 28, 202629
Nov 27, 202628
Nov 26, 202616
Nov 25, 202611
Nov 24, 202614
Nov 23, 202615
Nov 22, 202616
Nov 21, 202617
Nov 20, 202640
Nov 19, 202641
Nov 18, 202661
Nov 17, 202661
Nov 16, 202666
Nov 15, 202681
Nov 14, 2026148
Nov 13, 2026146
Nov 12, 2026151
Nov 11, 2026142
Nov 10, 2026155
Nov 9, 2026154
Nov 8, 2026139
Nov 7, 202689
Nov 6, 202691
Nov 5, 2026129
Nov 4, 2026119
Nov 3, 2026113
Nov 2, 2026133
Nov 1, 2026138
Oct 31, 2026126
Oct 30, 2026109
Oct 29, 202659
Oct 28, 202657
Oct 27, 202665
Oct 26, 202647
Oct 25, 202667
Oct 24, 2026245
Oct 23, 2026238
Oct 22, 2026246
Oct 21, 2026254
Oct 20, 2026252
Oct 19, 2026282
Oct 18, 2026456
Oct 17, 2026409
Oct 16, 2026751
Oct 15, 20261,086
Oct 14, 20262,281
Oct 13, 20262,264
Oct 12, 20262,226
Oct 11, 20262,025
Oct 10, 20261,888
Oct 9, 20261,546
Oct 8, 20261,203

Each point is npm's rolling 7-day download count.

Health Score

67/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1177993877-payload-plugin-json-form-builder.svg)](https://payloaddirectory.dev/plugins/1177993877-payload-plugin-json-form-builder)
HTML
<a href="https://payloaddirectory.dev/plugins/1177993877-payload-plugin-json-form-builder"><img src="https://payloaddirectory.dev/badge/1177993877-payload-plugin-json-form-builder.svg" alt="Payload Directory"></a>
Updated Dec 5, 2026Created Mar 10, 2026Published Dec 4, 2026

README

Payload JSON Form Builder

This plugin turns an ordinary json field into Payload components. An editor fills in text, picks images from Media, writes rich text, builds lists - and all of it lands back in the same json value, which your site reads as plain keys. The form those components make is built in the admin panel too: the plugin brings its own builder, where fields are added, renamed and reordered without a deploy.

The form a json field becomes

AI Integration Prompt

Copy and paste this prompt into your AI assistant (Cursor, Claude, etc.) to add the plugin to an existing Payload project.

I want to edit Payload json fields as real admin forms with
@focus-reactive/payload-plugin-json-form-builder. Follow these steps in order, and stop to ask me where a step says so.

## Rules you must follow

- Never write an access rule that admits every logged-in user: no `Boolean(req.user)`, no `() => true`,
  no `({ req }) => !!req.user`. A rule names a role, or it is `nobody`.
- Do not invent roles. Ask me which roles may build forms and who may read and edit the plugin's global.
- Write every policy entry by hand in `src/access.policy.ts`, and grant each capability and each
  collection right explicitly to the roles I name. Nothing is open by default.
- When the boot or a request fails, fix the cause or ask me. Never use `anyone`, a looser gate,
  `overrideAccess` or a removed or disabled check to make an error go away.
- Do not add `overrideAccess: true` anywhere, and do not add `access` to the plugin's global.

## How the plugin works

A `jsonField()` holds a form: its shape (which fields, their kinds and settings) and the values filled in.
Everyone who may update the document fills in values; only users with the `build` capability may change the shape.
The server enforces this on every write, over REST, GraphQL and the Local API as a user.
The plugin adds a global (`json-form` by default) that holds the library of shared sections and the rich text anchor.
Its read and update access come from the project's access policy.

## Step 1: install

pnpm add @focus-reactive/payload-plugin-json-form-builder @focus-reactive/payload-plugin-guard

Check that `payload` is 3.90 or later; if it is not, upgrade it first.

## Step 2: ask me about roles

Look at the auth collection named in `admin.user` and the roles it has.
Ask me: "Which roles may build and change forms?", "Which roles may read the json-form global?" and
"Which roles may edit the json-form global?"
Wait for my answers. Write each answer as a gate in the policy file in step 3.

## Step 3: the access policy file

Open `src/access.policy.ts`, or create it if the project has none, following the guard README
(`defineAccessPolicy`, `gate`, `filter`, `nobody`, `anyone`, checked with `satisfies AccessPolicy<Config>`).
If you create it, every collection and global of the config needs an entry: move each existing
`access` of the project into the file, and ask me for every rule you cannot read from the code.
Add these entries for this plugin:

globals: {
  "json-form": { read: <the gate from my second answer>, update: <the gate from my third answer> },
},
plugins: {
  "json-form-builder": { build: <the gate from my first answer> },
},

## Step 4: register the plugin and wrap the config

// payload.config.ts
import { buildConfig } from 'payload'
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import { jsonFormPlugin } from '@focus-reactive/payload-plugin-json-form-builder'
import { accessPolicy } from './access.policy'

export default withAccessPolicy(
  accessPolicy,
  buildConfig({
    // ...the existing config
    plugins: [
      jsonFormPlugin({ access: accessPolicy.plugins['json-form-builder'] }),
    ],
  })
)

Add `jsonField({ name: 'settings' })` to the collections or globals I name.
Run `pnpm payload generate:types` and `pnpm payload generate:importmap`.

## Step 5: verify, and show me the output

With the app running, send each request and show me the status code.
Every one of them must be refused. If one succeeds, the policy is wrong: stop and tell me.

1. Anonymous write to the plugin's global, expect 403:
   curl -i -X POST http://localhost:3000/api/globals/json-form -H 'Content-Type: application/json' -d '{}'
2. As a user who may update a document with a json field but may not build forms, PATCH that document
   with one more section in the field, for example
   {"settings":[...the current sections, {"name":"extra","type":"text","value":""}]}, expect 403.
3. As the same user, PATCH the value of a field marked `readOnly`, expect 403.

Then, as the same user, change a text value in the form and save: it must succeed.
As a user who may build forms, add a field in the builder and save: it must succeed.

Installation

pnpm add @focus-reactive/payload-plugin-json-form-builder @focus-reactive/payload-plugin-guard
pnpm payload generate:importmap

The plugin is built on @focus-reactive/payload-plugin-guard. Who may build forms, and who may read and edit the plugin's global, is written in the project's access policy file.

// src/access.policy.ts, the entries for this plugin
globals: {
  "json-form": { read: isStaff, update: isEditor },
},
plugins: {
  "json-form-builder": { build: isAdmin },
},
// payload.config.ts
export default withAccessPolicy(
  accessPolicy,
  buildConfig({
    plugins: [
      jsonFormPlugin({
        richText: { editor: lexicalEditor() },
        access: accessPolicy.plugins["json-form-builder"],
      }),
    ],
  })
);

// any collection or global
fields: [jsonField({ name: "settings" })];

isAdmin, isEditor and isStaff stand for gates on your own roles; the guard README shows how to write them.

How it works

Building a section describes it much the way you would describe a schema in code: every node has a kind, a key and a value. That description just does not live in your repository - it lives in the field. The plugin reads it and draws real Payload components, which are far nicer to work with than json in a textarea: fields are filled in, hidden, dragged, deleted, nearly everything an ordinary field allows.

There is one difference, and it is in your favour: a new section needs no migration. However many fields you add and however deeply you nest them, the database still holds one json field, and what leaves it is a plain object of keys.

// what is stored                            // what your site receives
[                                            {
  { "name": "hero",                            "hero": {
    "type": "collapsible",                       "title": "Hackathon",
    "fields": [                                  "live": true
      { "name": "title", "type": "text",       }
        "value": "Hackathon" },              }
      { "name": "live", "type": "checkbox",
        "value": true } ] }
]

The form is built in the builder: sections on the left, the palette of kinds on the right. Thirteen kinds - text, number, date, select, checkbox, upload, rich text, list, group, accordion, tabs - nested as deep as you like.

The builder

Options

jsonFormPlugin({
  // who may build and change forms: the gates from your access policy; required
  access: accessPolicy.plugins["json-form-builder"],

  // the library of reusable sections; off by default
  library: true,

  // the editor rich text is written with; without it the kind stays out of the palette
  richText: { editor: lexicalEditor() },

  // the collection the upload kind picks files from; media by default
  uploads: "media",

  // the global the plugin adds itself: it holds the rich text anchor and the library
  global: { slug: "json-form" },
});

Access

CapabilityLets a userAlso needs
buildchange the shape of a form: add, rename and remove fields, change kinds and settings (readOnly, required, options, limits, conditions), attach and detach shared sections, and write into read-only fieldsupdate access to the document that holds the form

Without build, a user who may update the document can do what the form itself offers:

  • fill in values of fields that are not read-only;
  • hide, reorder and delete sections that are not read-only;
  • add, duplicate, hide, reorder and delete list rows, where a new row is a blank or exact copy of an existing one.

On a document the user may not update, or one locked by another user, the form is read-only for everyone: inputs cannot be edited, sections and rows have no menu, and the builder (gear, Add field and the builder drawer) is not offered. A user with build can still switch between the Fields and JSON views there, and the JSON is read-only.

Anything else in the request is refused with 403, whether it comes from the admin, REST, GraphQL or the Local API with a user. The Local API without a user, or with overrideAccess: true on an update, is trusted and not checked. A new document may only carry the field's defaultValue, and restoring a version with another shape needs build.

Reads:

  • A user of the admin user collection gets the typed form; anyone else, including users of other auth collections, gets plain values without hidden fields and rows.
  • Rich text values are stored and returned as sanitized HTML. Only formatting, headings, lists, quotes, rules and links with http, https, mailto, tel or relative addresses are kept, so your site can render them as HTML.
  • An upload value is resolved to the file's document only when the reader may read that document; otherwise it stays its url.
  • A section that follows the library takes the library's shape only for a reader who may read the library's global; anyone else gets the copy the document holds.

What the plugin owns

SlugKindWritten byRead by
json-form (or global.slug)globalyour policy's updateyour policy's read

global: false leaves the global out, and with it the policy entry.

library - reusable sections

Even without it the plugin gives you a global where sections are built and rendered on the site. The library is about something else: sections that repeat across many pages.

It works as a reference. In the library you build a section - its form and, where it helps, default values. Any json field can then point at it: the values there are its own and are edited as usual, while the form comes from the library. The form can only be changed there - add a field and it appears in every page that points at the section.

// the library: either in the plugin's own global
jsonFormPlugin({ library: true })

// or as a field of your own, beside what it shares with
fields: [
  { type: 'group', label: 'Components', fields: [jsonField({ name: 'components' })] },
  { type: 'group', label: 'Shared sections', fields: [jsonLibraryField()] },
]

// a field that may point at them
jsonField({ name: 'settings', shares: true })

In that field's builder, two groups appear under Add section: Attached sections, each with a ×, and Shared sections, each with a +. In the form, an attached section carries a global chip.

Migrating from 1.x

2.0 moves the plugin onto @focus-reactive/payload-plugin-guard; Upgrading to the guard explains the model all the plugins share, with a complete example. Every access rule is now written by hand in your project's src/access.policy.ts, and nothing is open by default: an entry you leave out stops the boot, and a capability you do not grant is refused for everyone.

What changes

  • Payload and every @payloadcms/* package 3.90 or later, with the React and Next versions Payload 3.90 requires, Node 22.22 or later, and @focus-reactive/payload-plugin-guard installed next to the plugin.
  • access is a required option with no default.
  • The build option of jsonFormPlugin and of jsonField is gone, and so is the BuildGate type: the rule is the build gate in the policy, and it applies to every json field.
  • global.access is gone: the global's access comes from the policy entry for its slug.
  • Who may build is enforced on the server: a request that changes the shape of a form without build is refused with 403, over REST, GraphQL and the Local API as a user.
  • Rich text values are sanitized when they are saved and when they are read.
  • Users of other auth collections get plain values instead of the typed form, uploads are resolved only when the reader may read them, and the library is followed only for readers who may read its global.
  • jsonField() needs the plugin: a json field read or written without it throws.

Steps

  1. Upgrade payload and every @payloadcms/* package to 3.90 or later, run the server on Node 22.22 or later, and install the guard: pnpm add @focus-reactive/payload-plugin-guard @focus-reactive/payload-plugin-json-form-builder.

  2. Add the plugin's entries to src/access.policy.ts, with gates for your own roles; if the project has no policy file yet, write it first as the guide describes.

    // src/access.policy.ts, inside defineAccessPolicy({ ... })
    globals: {
      "json-form": { read: panelUser, update: isEditor },
    },
    plugins: {
      "json-form-builder": { build: isAdmin },
    },
    
    • build: change the shape of a form (add, rename and remove fields, change kinds and settings, attach and detach shared sections) and write into read-only fields; the user also needs update access to the document.
    • json-form (or the slug in global.slug): the library of shared sections; read decides who may use them in forms, update who edits the library.
  3. Pass access: accessPolicy.plugins["json-form-builder"] to jsonFormPlugin, and export the config wrapped: export default withAccessPolicy(accessPolicy, buildConfig({ ... })).

  4. Database: no migration; the global and the json fields keep their columns.

  5. Re-test: as a user without build, a REST PATCH that adds a field to a form answers 403 while one that only fills in values succeeds; a stored rich text value with a <script> comes back sanitized; then build a form as a user with build and fill it in as an editor.

Compatibility

PayloadPlugin
3.90+2.x
3.84+1.x

License

MIT

Similar plugins