Skip to content

Commit 6cb7969

Browse files
committed
fix: add readme for plugin
1 parent b507d30 commit 6cb7969

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# JSON Editor
2+
3+
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.
4+
5+
Values support all standard JSON types: strings, numbers, booleans, `null`, arrays, and nested objects.
6+
7+
## Installation
8+
9+
```bash
10+
pnpm install @adminforth/json-editor --save
11+
```
12+
13+
## Setting up
14+
15+
Import and attach the plugin to an existing column in your resource:
16+
17+
```ts title="./your_resourse"
18+
//diff-add
19+
import JsonEditorPlugin from '@adminforth/json-editor';
20+
21+
export default {
22+
...
23+
plugins: [
24+
...
25+
//diff-add
26+
new JsonEditorPlugin({
27+
//diff-add
28+
fieldName: 'description',
29+
//diff-add
30+
}),
31+
],
32+
}
33+
```
34+
35+
> 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.
36+
37+
## Value types
38+
39+
Values are entered in JSON notation:
40+
41+
| Input | Saved as |
42+
|---|---|
43+
| `"hello"` | string |
44+
| `42` | number |
45+
| `true` / `false` | boolean |
46+
| `null` | null |
47+
| `[1, "x", true]` | array |
48+
| `{"key": 1}` | nested object |
49+
50+
## Validation
51+
52+
Saving is blocked when:
53+
54+
- **Duplicate keys** - two rows share the same key name.
55+
- **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`.
56+
57+
An empty value field is allowed and saved as an empty string `""`.

0 commit comments

Comments
 (0)