Gathering detailed insights and metrics for vue3-ts-jsoneditor
Gathering detailed insights and metrics for vue3-ts-jsoneditor
Gathering detailed insights and metrics for vue3-ts-jsoneditor
Gathering detailed insights and metrics for vue3-ts-jsoneditor
vanilla-jsoneditor
A web-based tool to view, edit, format, transform, and validate JSON
ang-jsoneditor
[![Build Status](https://travis-ci.org/mariohmol/ang-jsoneditor.svg?branch=master)](https://travis-ci.org/mariohmol/ang-jsoneditor)
jsoneditor
A web-based tool to view, edit, format, and validate JSON
jsoneditor-standalone
This is a wrapper for jsoneditor package, it can be run offline without any dependencies and privacy concerns.
npm install vue3-ts-jsoneditor
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
52 Stars
200 Commits
9 Forks
3 Watching
3 Branches
3 Contributors
Updated on 16 Oct 2024
Minified
Minified + Gzipped
Vue (63.39%)
TypeScript (32.68%)
Shell (1.33%)
CSS (1.11%)
HTML (0.81%)
JavaScript (0.68%)
Cumulative downloads
Total Downloads
Last day
44.8%
656
Compared to previous day
Last week
6.3%
2,378
Compared to previous week
Last month
35%
9,745
Compared to previous month
Last year
116%
104,406
Compared to previous year
3
19
you can 👀 a live demo here
You can use this module
1npm install vue3-ts-jsoneditor
1import {createApp} from 'vue'; 2import App from './App.vue'; 3import {JsonEditorPlugin} from 'vue3-ts-jsoneditor'; 4 5const app = createApp(App); 6 7app.use(JsonEditorPlugin, { 8 componentName: '/componentName/', // Default: 'JsonEditor', 9 options: { 10 /** 11 * 12 * SET GLOBAL OPTIONS 13 * 14 * */ 15 } 16}); 17 18app.mount('#app');
1interface JSONEditorOptions { 2 readOnly?: boolean; 3 indentation?: number | string; 4 tabSize?: number; 5 selection?: JSONEditorSelection; 6 mode?: Mode; 7 mainMenuBar?: boolean; 8 navigationBar?: boolean; 9 statusBar?: boolean; 10 askToFormat?: boolean; 11 escapeControlCharacters?: boolean; 12 escapeUnicodeCharacters?: boolean; 13 flattenColumns?: boolean; 14 validator?: Validator; 15 parser?: JSONParser; 16 validationParser?: JSONParser; 17 pathParser?: JSONPathParser; 18 queryLanguagesIds?: QueryLanguageId[]; 19 queryLanguageId?: QueryLanguageId; 20 onRenderValue?: OnRenderValue; 21 onClassName?: OnClassName; 22 onRenderMenu?: OnRenderMenu; 23 height?: string | number; 24 fullWidthButton?: boolean; 25 darkTheme?: boolean; 26} 27 28type Mode = "text" | "tree" | "table"; 29 30type QueryLanguageId = 'javascript' | 'lodash' | 'jmespath';
Read more in svelte-jsoneditor properties
1<script setup> 2 import JsonEditor from 'vue3-ts-jsoneditor'; 3</script>
1// You can use the "v-model:json" and pass json value 2<template> 3 <json-editor 4 height="400" 5 mode="tree" 6 :queryLanguagesIds="queryLanguages" 7 v-model:json="jsonData" 8 @error="onError" 9 @focus="onFocus" 10 @blur="onBlur" 11 /> 12</template> 13 14// or you can use the "v-model:text" and pass json string 15 16<template> 17 <json-editor 18 height="400" 19 mode="text" 20 v-model:text="jsonText" 21 /> 22</template> 23 24// or you can use the "v-model" and pass json value. "mode" should be "tree"!!! 25 26<template> 27 <json-editor 28 height="400" 29 mode="tree" 30 v-model="jsonData" 31 /> 32</template> 33 34// or you can use the "v-model" and pass json string. "mode" should be "text"!!! 35 36<template> 37 <json-editor 38 height="400" 39 mode="text" 40 v-model="jsonText" 41 /> 42</template> 43 44<script setup lang="ts"> 45 import {ref} from 'vue'; 46 47 const jsonData = ref({ 48 array: [1, 2, 3], 49 boolean: true, 50 Null: null, 51 number: 123, 52 seconds: 0, 53 object: {a: 'b', c: 'd'}, 54 string: 'Hello World', 55 }); 56 57 const jsonText = ref('{"array": [1, 2, 3]}'); 58 59 const queryLanguages = ref(['javascript', 'lodash', 'jmespath']); 60 61 const onError = (error) => { 62 // 63 } 64 65 const onFocus = () => { 66 // 67 } 68 69 const onBlur = () => { 70 // 71 } 72</script>
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.
Slot | Description |
---|---|
default | Slot content displayed before the editor is rendered. Useful for SSR |
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 |
selection (v-model) | The current selected contents. You can use two-way binding using bind:selection. The tree mode supports MultiSelection, KeySelection, ValueSelection, InsideSelection, or AfterSelection. The table mode supports ValueSelection, and text mode supports TextSelection. | JSONEditorSelection | null | null |
mode | mode: 'tree', 'text' or 'table'. Open the editor in 'tree' mode (default), 'table' mode, or 'text' 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 |
askToFormat | When true (default), the user will be asked whether he/she wants to format the JSON document when a compact document is loaded or pasted in 'text' mode. Only applicable to 'text' mode. | 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 |
flattenColumns | Only applicable to 'table' mode. When true, nested object properties will be displayed each in their own column, with the nested path as column name. When false, nested objects will be rendered inline, and double-clicking them will open them in a popup. | boolean | true |
validator | Validate the JSON document. Details in svelte-jsoneditor | function (json: unknown): ValidationError[] | |
parser | Configure a custom JSON parser, like lossless-json. By default, the native JSON parser of JavaScript is used. The JSON interface is an object with a parse and stringify function | JSONParser | undefined |
validationParser | Only applicable when a validator is provided. This is the same as parser, except that this parser is used to parse the data before sending it to the validator. Configure a custom JSON parser that is used to parse JSON before passing it to the validator. By default, the built-in JSON parser is used. When passing a custom validationParser, make sure the output of the parser is supported by the configured validator. | JSONParser | undefined |
pathParser | An optional object with a parse and stringify method to parse and stringify a JSONPath, which is an array with property names. The pathParser is used in the path editor in the navigation bar, which is opened by clicking the edit button on the right side of the navigation bar. The pathParser.parse function is allowed to throw an Error when the input is invalid. By default, a JSON Path notation is used, which looks like $.data[2].nested.property. | JSONPathParser | undefined |
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 | function (props: RenderValueProps) : RenderValueComponentDescription[] | |
onRenderMenu | Details in svelte-jsoneditor | function (items: MenuItem[], context: { mode: 'tree' | 'text' | 'table', modal: boolean }) : MenuItem[] | undefined | |
fullWidthButton | Whether full screen switching is added | boolean | true |
height | Default height | string | number | undefined |
darkTheme | Switch to dark theme | boolean | false |
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' | 'table') |
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. | () |
expand()
get()
update()
. See more about set()
update()
updateProps()
refresh()
focus()
destroy()
patch()
transform()
scrollTo()
findElement()
acceptAutoRepair()
validate()
1<template> 2 <json-editor 3 height="400" 4 ref="editor" 5 v-model:json="jsonData" 6 /> 7 8 <div> 9 <button @click="onCollapse">collapse all</button> 10 11 <button @click="onExpand">expand all</button> 12 </div> 13</template> 14 15<script setup lang="ts"> 16 import {ref} from 'vue'; 17 18 const jsonData = ref({ 19 array: [1, 2, 3], 20 boolean: true, 21 Null: null, 22 number: 123, 23 seconds: 0, 24 object: {a: 'b', c: 'd'}, 25 string: 'Hello World', 26 }); 27 28 const editor = ref(); 29 30 const onCollapse = () => { 31 editor.value.$collapseAll(); 32 }; 33 34 const onExpand = () => { 35 editor.value.$expandAll(); 36 }; 37</script>
The editor can be styled using the available CSS variables. A full list with all variables can be found here
1<template> 2 <json-editor 3 class="awesome-json-editor" 4 height="400" 5 v-model:json="jsonData" 6 /> 7</template> 8 9<script setup lang="ts"> 10import {ref} from 'vue'; 11 12const jsonData = ref({ 13 array: [1, 2, 3], 14 boolean: true, 15 Null: null, 16 number: 123, 17 seconds: 0, 18 object: {a: 'b', c: 'd'}, 19 string: 'Hello World', 20}); 21 22</script> 23 24<style> 25.awesome-json-editor { 26 /* define a custom theme color */ 27 /* over all fonts, sizes, and colors */ 28 --jse-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, 29 Cantarell, 'Helvetica Neue', sans-serif; 30 /* "consolas" for Windows, "menlo" for Mac with fallback to "monaco", 'Ubuntu Mono' for Ubuntu */ 31 /* (at Mac this font looks too large at 14px, but 13px is too small for the font on Windows) */ 32 --jse-font-family-mono: consolas, menlo, monaco, 'Ubuntu Mono', 'source-code-pro', monospace; 33 --jse-font-size-mono: 14px; 34 --jse-font-size: 16px; 35 --jse-font-size-text-mode-search: 80%; 36 --jse-line-height: calc(1em + 4px); 37 --jse-indent-size: calc(1em + 4px); 38 --jse-color-picker-button-size: 1em; 39 --jse-padding: 10px; 40 --jse-theme-color: #3883fa; 41 --jse-theme-color-highlight: #5f9dff; 42 --jse-background-color: #fff; 43 --jse-text-color: #4d4d4d; 44 --jse-text-color-inverse: #fff; 45 --jse-error-color: #ee5341; 46 --jse-warning-color: #fdc539; 47 48 /* main, menu, modal */ 49 --jse-main-border: 1px solid #d7d7d7; 50 --jse-menu-color: var(--jse-text-color-inverse); 51 --jse-menu-button-size: 32px; 52 --jse-modal-background: #f5f5f5; 53 --jse-modal-overlay-background: rgba(0, 0, 0, 0.3); 54 --jse-modal-code-background: rgba(0, 0, 0, 0.05); 55 56 /* panels: navigation bar, gutter, search box */ 57 --jse-panel-background: #ebebeb; 58 --jse-panel-color: var(--jse-text-color); 59 --jse-panel-color-readonly: #b2b2b2; 60 --jse-panel-border: var(--jse-main-border); 61 --jse-panel-button-color: inherit; 62 --jse-panel-button-background: transparent; 63 --jse-panel-button-color-highlight: var(--jse-text-color); 64 --jse-panel-button-background-highlight: #e0e0e0; 65 66 /* navigation-bar */ 67 --jse-navigation-bar-color: #656565; 68 --jse-navigation-bar-background: var(--jse-background-color); 69 --jse-navigation-bar-background-highlight: #e5e5e5; 70 --jse-navigation-bar-dropdown-color: #656565; 71 72 /* context menu */ 73 --jse-context-menu-background: #656565; 74 --jse-context-menu-background-highlight: #7a7a7a; 75 --jse-context-menu-color: var(--jse-text-color-inverse); 76 --jse-context-menu-color-disabled: #9d9d9d; 77 --jse-context-menu-separator-color: #7a7a7a; 78 --jse-context-menu-button-background: var(--jse-context-menu-background); 79 --jse-context-menu-button-background-highlight: var(--jse-context-menu-background-highlight); 80 --jse-context-menu-button-color: var(--jse-context-menu-color); 81 --jse-context-menu-button-size: calc(1em + 4px); 82 --jse-context-menu-tip-background: rgba(255, 255, 255, 0.2); 83 --jse-context-menu-tip-color: inherit; 84 85 /* contents: json key and values */ 86 --jse-key-color: #1a1a1a; 87 --jse-value-color: #1a1a1a; 88 --jse-value-color-number: #ee422e; 89 --jse-value-color-boolean: #ff8c00; 90 --jse-value-color-null: #004ed0; 91 --jse-value-color-string: #008000; 92 --jse-value-color-url: #008000; 93 --jse-delimiter-color: rgba(0, 0, 0, 0.38); 94 --jse-edit-outline: 2px solid #656565; 95 96 /* contents: selected or hovered */ 97 --jse-hover-background-color: rgba(0, 0, 0, 0.06); 98 --jse-selection-background-color: #d3d3d3; 99 --jse-selection-background-light-color: #e8e8e8; 100 101 /* contents: section of collapsed items in an array */ 102 --jse-collapsed-items-background-color: #f5f5f5; 103 --jse-collapsed-items-selected-background-color: #c2c2c2; 104 --jse-collapsed-items-link-color: rgba(0, 0, 0, 0.38); 105 --jse-collapsed-items-link-color-highlight: #ee5341; 106 107 /* contents: highlighting of search matches */ 108 --jse-search-match-color: #ffe665; 109 --jse-search-match-outline: 1px solid #ffd700; 110 --jse-search-match-active-color: #ffd700; 111 --jse-search-match-active-outline: 1px solid #e1be00; 112 113 /* contents: inline tags inside the JSON document */ 114 --jse-tag-background: rgba(0, 0, 0, 0.2); 115 --jse-tag-color: var(--jse-text-color-inverse); 116 117 /* controls in modals: inputs, buttons, and `a` */ 118 --jse-controls-box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.24); 119 --jse-input-background: var(--jse-background-color); 120 --jse-input-background-readonly: transparent; 121 --jse-input-border: 1px solid #d8dbdf; 122 --jse-input-border-focus: 1px solid var(--jse-theme-color); 123 --jse-input-radius: 3px; 124 --jse-button-background: #e0e0e0; 125 --jse-button-background-highlight: #e7e7e7; 126 --jse-button-color: var(--jse-text-color); 127 --jse-button-primary-background: var(--jse-theme-color); 128 --jse-button-primary-background-highlight: var(--jse-theme-color-highlight); 129 --jse-button-primary-background-disabled: #9d9d9d; 130 --jse-button-primary-color: var(--jse-text-color-inverse); 131 --jse-a-color: #156fc5; 132 --jse-a-color-highlight: #0f508d; 133 134 /* messages */ 135 --jse-message-error-background: var(--jse-error-color); 136 --jse-message-error-color: var(--jse-text-color-inverse); 137 --jse-message-warning-background: #ffde5c; 138 --jse-message-warning-color: var(--jse-text-color); 139 --jse-message-success-background: #9ac45d; 140 --jse-message-success-color: var(--jse-text-color-inverse); 141 --jse-message-info-background: #9d9d9d; 142 --jse-message-info-color: var(--jse-text-color-inverse); 143 --jse-message-action-background: rgba(255, 255, 255, 0.2); 144 --jse-message-action-background-highlight: rgba(255, 255, 255, 0.3); 145 146 /* svelte-select */ 147 --itemIsActiveBG: #3883fa; 148 --border: 1px solid #d8dbdf; 149 --borderRadius: 3px; 150 --background: #fff; 151 152 /* color picker */ 153 --jse-color-picker-background: var(--jse-panel-background); 154 --jse-color-picker-border-box-shadow: #cbcbcb 0 0 0 1px; 155} 156</style>
1# install dependencies 2npm install 3 4# serve with hot reload at localhost:3080 5npm run dev 6 7# build for production with minification 8npm run build
No vulnerabilities found.
No security vulnerabilities found.