Skip to content

Commit 728c334

Browse files
authored
Merge pull request #664 from devforth/feature/AdminForth/1704/create-json-editor-plugin
fix: add documentation for af edit json field plugin
2 parents 01b530b + c121291 commit 728c334

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: JSON Editor
3+
description: "Guide to the JSON Editor plugin — add, edit and delete key-value pairs stored as a JSON object in a database column."
4+
slug: /tutorial/Plugins/json-editor
5+
---
6+
7+
# JSON Editor
8+
9+
The JSON Editor plugin replaces the default text input for JSON columns with a structured key-value editor. Users can add, edit, and delete individual pairs without writing raw JSON.
10+
11+
Values support all standard JSON types: strings, numbers, booleans, `null`, arrays, and nested objects.
12+
13+
## Installation
14+
15+
```bash
16+
pnpm install @adminforth/json-editor --save
17+
```
18+
19+
## Setting up
20+
21+
Import and attach the plugin to an existing column in your resource:
22+
23+
```ts title="./resources/apartments.ts"
24+
//diff-add
25+
import JsonEditorPlugin from '@adminforth/json-editor';
26+
27+
export default {
28+
...
29+
plugins: [
30+
...
31+
//diff-add
32+
new JsonEditorPlugin({
33+
//diff-add
34+
fieldName: 'description',
35+
//diff-add
36+
}),
37+
],
38+
}
39+
```
40+
41+
> The plugin works on columns with type `json`, `string`, or `text`. The stored value must be a JSON object (`{}`). Top-level arrays and primitives are not supported.
42+
43+
![alt text](json-plugin-example.png)
44+
45+
## Value types
46+
47+
Values are entered in JSON notation:
48+
49+
| Input | Saved as |
50+
|---|---|
51+
| `"hello"` | string |
52+
| `42` | number |
53+
| `true` / `false` | boolean |
54+
| `null` | null |
55+
| `[1, "x", true]` | array |
56+
| `{"key": 1}` | nested object |
57+
58+
## Validation
59+
60+
Saving is blocked when:
61+
62+
- **Duplicate keys** - two rows share the same key name.
63+
- **Invalid JSON value** - the value field is not valid JSON (e.g. `hello` without quotes). The error identifies the row: `Row 2: value is not valid JSON`.
64+
65+
An empty value field is allowed and saved as an empty string `""`.
13 KB
Loading

0 commit comments

Comments
 (0)