[](https://badge.fury.io/js/vue3-ts-jsoneditor)


## πΊπ¦πΊπ¦πΊπ¦ [Stand With Ukraine](https://www.standwithukraine.how/) πΊπ¦πΊπ¦πΊπ¦
# vue3-ts-jsoneditor
#### Powered by [svelte-jsoneditor](https://www.npmjs.com/package/svelte-jsoneditor)
### π Advantages
- SSR support
- Full width button
- Automatic dynamic import of query languages
- Automatic dynamic import of dark theme
## πΉ Demo
> you can π a live demo [here](https://bestkolobok.github.io/vue3-jsoneditor/)
## βοΈ Installation
```bash
npm install vue3-ts-jsoneditor
```
## β Using
### π Import globally
```javascript
import {createApp} from 'vue';
import App from './App.vue';
import vue3TsJsoneditor from 'vue3-ts-jsoneditor';
const app = createApp(App);
app.use(vue3TsJsoneditor, {
componentName: '/componentName/', // Default: 'JsonEditor',
options: {
/**
*
* SET GLOBAL OPTIONS
*
* */
}
});
app.mount('#app');
```
### π Global options
```typescript
interface JSONEditorOptions {
readOnly?: boolean;
indentation?: number | string;
tabSize?: number;
mode?: Mode;
mainMenuBar?: boolean;
navigationBar?: boolean;
statusBar?: boolean;
escapeControlCharacters?: boolean;
escapeUnicodeCharacters?: boolean;
validator?: Validator;
queryLanguagesIds?: QueryLanguageId[];
queryLanguageId?: QueryLanguageId;
onRenderValue?: OnRenderValue;
onClassName?: OnClassName;
onRenderMenu?: OnRenderMenu;
height?: string | number;
fullWidthButton?: boolean;
darkTheme?: boolean;
}
type Mode = "text" | "tree";
type QueryLanguageId = 'javascript' | 'lodash' | 'jmespath';
```
Read more in [svelte-jsoneditor](https://www.npmjs.com/package/svelte-jsoneditor) properties
### π Import locally
```javascript
```
### π Use in template
```vue
// You can use the "v-model:json" and pass json value
// or you can use the "v-model:text" and pass json string
// or you can use the "v-model" and pass json value. "mode" should be "tree"!!!
// or you can use the "v-model" and pass json string. "mode" should be "text"!!!
```
### βοΈβοΈβοΈ Important
> If you want use v-model (not v-model:json or v-model:text) then the type of data depends on the mode of the editor.
> If mode="tree", then the data type in the model is JSON value, if mode="text",
> then the data type is JSON string.
> Please be aware that in text mode v-model can contain invalid JSON: whilst typing in text mode,
> a JSON document will be temporarily invalid, like when the user is typing a new string.
>
> It is more clear to use v-model:json for tree mode and v-model:text for text mode.
### βοΈ Slots
| Slot | Description |
| ---------- | ------------------ |
| default | Slot content displayed before the editor is rendered. Useful for SSR |
### βοΈ Props
| Name | Description | type | default |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------: | :-----------------: |
| json (v-model) | JSON value | object | array | true | false | null | number | string | undefined |
| text (v-model) | JSON string | string | undefined |
| modelValue (v-model) | JSON value or JSON string | object | array | true | false | null | number | string | undefined |
| value | Same as modelValue | object | array | true | false | null | number | string | undefined |
| mode | Open the editor in 'tree' mode or 'text' mode (formerly: code mode). | string | 'tree' |
| mainMenuBar | Show the main menu bar. Default value is true. | boolean | true |
| navigationBar | Show the navigation bar with, where you can see the selected path and navigate through your document from there. | boolean | true |
| statusBar | Show a status bar at the bottom of the 'text' editor, showing information about the cursor location and selected contents. | boolean | true |
| readOnly | Open the editor in read-only mode: no changes can be made, non-relevant buttons are hidden from the menu, and the context menu is not enabled. | boolean | false |
| indentation | Number of spaces use for indentation when stringifying JSON, or a string to be used as indentation like '\t' to use a tab as indentation, or ' ' to use 4 spaces (which is equivalent to configuring indentation: 4). See also property tabSize. | number | string | 4 |
| tabSize | When indentation is configured as a tab character (indentation: '\t'), tabSize configures how large a tab character is rendered. Default value is 4. Only applicable to text mode. | number | 4 |
| escapeControlCharacters | When true, control characters like newline and tab are rendered as escaped characters \n and \t. Only applicable for 'tree' mode, in 'text' mode control characters are always escaped. | boolean | false |
| escapeUnicodeCharacters | When true, unicode characters like β and π are rendered escaped like \u260e and \ud83d\ude00 | boolean | false |
| validator | Validate the JSON document. Details in [svelte-jsoneditor](https://www.npmjs.com/package/svelte-jsoneditor) | function (json: JSONValue): ValidationError[] | |
| queryLanguagesIds | Configure one or multiple query language that can be used in the Transform modal. The library comes with three languages: javascript, lodash or jmespath | QueryLanguage[] | [javascript] |
| queryLanguageId | The id of the currently selected query language javascript, lodash or jmespath | string | |
| onClassName | Add a custom class name to specific nodes, based on their path and/or value. | function (path: Path, value: any): string | undefined | |
| onRenderValue | Details in [svelte-jsoneditor](https://www.npmjs.com/package/svelte-jsoneditor) | function (props: RenderValueProps) : RenderValueComponentDescription[] | |
| onRenderMenu | Details in [svelte-jsoneditor](https://www.npmjs.com/package/svelte-jsoneditor) | function (mode: 'tree' | 'text', items: MenuItem[]) : MenuItem[] | undefined | |
| fullWidthButton | Whether full screen switching is added | boolean | true |
| height | Default height | string | number | undefined |
| darkTheme | Switch to dark theme | boolean | false |
### βοΈ Events
| Name | Description | Arguments |
| ------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| change | Which is invoked on every change made in the JSON document. The parameter patchResult is only available in tree mode, and not in text mode, since a change in arbitrary text cannot be expressed as a JSON Patch document.| (content: Content, previousContent: Content, patchResult: JSONPatchResult | null) |
| error | Event fired when an error occurs. Default implementation is to log an error in the console and show a simple alert message to the user. | (err: Error) |
| change-mode | Invoked when the mode is changed. | (mode: 'tree' | 'text') |
| change-query-language | Invoked when the user changes the selected query language in the TransformModal via the configuration button top right. | (queryLanguageId: string) |
| focus | Fired when the editor got focus. | () |
| blur | Fired when the editor lost focus. | () |
### βοΈ Use expose functions
- $collapseAll - collapse all nodes
- $expandAll - expand all nodes
- $expand - Expand or collapse paths in the editor. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about expand()
- $get - Get the current JSON document. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about get()
- $set - Replace the current content. Will reset the state of the editor. See also method update(). [See more](https://www.npmjs.com/package/svelte-jsoneditor) about set()
- $update - Update the loaded content, keeping the state of the editor (like expanded objects). [See more](https://www.npmjs.com/package/svelte-jsoneditor) about update()
- $updateProps - Update some or all of the properties [See more](https://www.npmjs.com/package/svelte-jsoneditor) about updateProps()
- $refresh - Refresh rendering of the contents, for example after changing the font size. This is only available in text mode. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about refresh()
- $focus - Give the editor focus. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about focus()
- $patch - Apply a JSON patch document to update the contents of the JSON document. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about patch()
- $transform - Programmatically trigger clicking of the transform button in the main menu, opening the transform model. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about transform()
- $scrollTo - Scroll the editor vertically such that the specified path comes into view. The path will be expanded when needed. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about scrollTo()
- $findElement - Find the DOM element of a given path. Returns null when not found. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about findElement()
- $acceptAutoRepair - In tree mode, invalid JSON is automatically repaired when loaded. [See more](https://www.npmjs.com/package/svelte-jsoneditor) about acceptAutoRepair()
```vue