Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

svelte-jsoneditor

> 前端框架
Open source

A web-based tool to view, edit, format, repair, query, transform, and validate JSON

1.3K stars0 likes1 views
WebsiteGitHub

About

A web-based tool to view, edit, format, repair, query, transform, and validate JSON

svelte-jsoneditor

A web-based tool to view, edit, format, transform, and validate JSON.

Try it out:

The library is written with Svelte, but can be used in plain JavaScript too and in any framework (SolidJS, React, Vue, Angular, etc.). It requires a browser from March 2022 or newer.

Features

  • View and edit JSON
  • Has a low level text editor and high level tree view and table view
  • Format (beautify) and compact JSON
  • Sort, query, filter, and transform JSON
  • Repair JSON
  • JSON schema validation and pluggable custom validation
  • Color highlighting, undo/redo, search and replace
  • Utilities like a color picker and timestamp tag
  • Handles large JSON documents up to 512 MB

Install

For usage in a Svelte project:

bash
npm install svelte-jsoneditor

Note that [email protected] requires Svelte 5. If you use Svelte 3 or 4, install [email protected].

For usage in vanilla JavaScript or frameworks like SolidJS, React, Vue, Angular, etc:

bash
npm install vanilla-jsoneditor

For details on individual releases, see the changelog at https://github.com/josdejong/svelte-jsoneditor/releases.

Use

Examples

  • Svelte:
    • Playground: https://stackblitz.com/edit/svelte-jsoneditor-basic-usage
    • Examples: /src/routes/examples
  • Plain JavaScript examples:
    • Try it out: https://stackblitz.com/edit/svelte-jsoneditor-plain-javascript
    • Examples: /examples/browser
  • React example: https://stackblitz.com/edit/svelte-jsoneditor-in-react
  • Vue example: https://stackblitz.com/edit/svelte-jsoneditor-in-vue

Svelte usage

Create a JSONEditor with two-way binding bind:json:

xml

Or one-way binding:

xml

Vanilla bundle (use in React, Vue, Angular, plain JavaScript, ...)

The library provides a vanilla bundle of the editor via the npm library vanilla-jsoneditor (instead of svelte-jsoneditor) which can be used in any browser environment and framework. In a framework like React, Vue, or Angular, you'll need to write some wrapper code around the class interface.

If you have a setup for your project with a bundler (like Vite, Rollup, or Webpack), it is best to use the default ES import:

typescript
// for use in a React, Vue, or Angular project
import { JSONEditor } from 'vanilla-jsoneditor'

If you want to use the library straight in the browser, use the provided standalone ES bundle:

typescript
// for use directly in the browser
import { createJSONEditor } from 'vanilla-jsoneditor/standalone.js'

The standalone bundle contains all dependencies of vanilla-jsoneditor, for example lodash-es and Ajv. If you use some of these dependencies in your project too, it means that they will be bundled twice in your web application, leading to a needlessly large application size. In general, it is preferable to use the default import { createJSONEditor } from 'vanilla-jsoneditor' instead of the standalone bundle so dependencies can be reused.

Browser example loading the standalone ES module:

xml

  
    JSONEditor
  
  
    

    

  

Wrapper libraries for specific frameworks

To make it easier to use the library in your framework of choice, you can use a wrapper library:

  • Vue:
    • json-editor-vue
    • vue3-ts-jsoneditor
  • Django:
    • django-svelte-jsoneditor

API

constructor

Svelte component:

xml

JavasScript class:

javascript
import { createJSONEditor } from 'vanilla-jsoneditor' // or 'vanilla-jsoneditor/standalone.js'

const content = { text: '[1,2,3]' }

const editor = createJSONEditor({
  target: document.getElementById('jsoneditor'),
  props: {
    content,
    onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
      // content is an object { json: unknown } | { text: string }
      console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult })
    }
  }
})

properties

Properties such as content and mode are either passed as attributes to the Svelte component, like ``, or via the props in case of the vanilla JS factory function: createJSONEditor({ target, props: { content, mode }.

content

typescript
content: Content

Pass the JSON contents to be rendered in the JSONEditor. Content is an object containing a property json (a parsed JSON document) or text (a stringified JSON document). Only one of the two properties must be defined. You can pass both content types to the editor independent of in what mode it is. You can use two-way binding via bind:content.

IMPORTANT: only make immutable changes to content. Mutable changes will mess up history and rendered contents. See section Immutability.

selection

typescript
selection: JSONEditorSelection | undefined

The current selected contents. You can use two-way binding using bind:selection. The tree mode supports MultiSelection, KeySelection, EditKeySelection, ValueSelection, EditValueSelection, InsideSelection, or AfterSelection. The table mode supports ValueSelection, and text mode supports TextSelection..

mode

typescript
mode: 'tree' | 'text' | 'table'

Open the editor in 'tree' mode (default), 'table' mode, or 'text' mode (formerly: code mode).

ariaLabel

typescript
ariaLabel: string

The accessible name of the editor, applied to the contents of all three modes. Default value is 'JSON editor'. Give each editor a name of its own when a page contains more than one, so screen reader users can tell them apart.

mainMenuBar

typescript
mainMenuBar: boolean

Show the main menu bar. Default value is true.

navigationBar

typescript
navigationBar: boolean

Show the navigation bar with, where you can see the selected path and navigate through your document from there. Default value is true.

statusBar

typescript
statusBar: boolean

Show a status bar at the bottom of the 'text' editor, showing information about the cursor location and selected contents. Default value is true.

askToFormat

typescript
askToFormat: boolean

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.

readOnly

typescript
readOnly: boolean

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. Default value is false.

indentation

typescript
indentation: number | string

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.

tabSize

typescript
tabSize: number

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.

truncateTextSize

typescript
truncateTextSize: number

JSON values containing a string with a length greater than truncateTextSize bytes will be truncated in tree mode and table mode. The text can be expanded by clicking the button "Show more" at the end of the string. The default value is 1000 bytes.

escapeControlCharacters

typescript
escapeControlCharacters: boolean

False by default. 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.

escapeUnicodeCharacters

typescript
escapeUnicodeCharacters: boolean

False by default. When true, unicode characters like ☎ and are rendered escaped like \u260e and \ud83d\ude00.

flattenColumns

typescript
flattenColumns: boolean

True by default. 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.

validator

typescript
validator: function (json: unknown): ValidationError[]

Validate the JSON document.

Using Ajv for JSON Schema

You can use the built-in JSON Schema validator powered by Ajv:

javascript
import { createAjvValidator } from 'svelte-jsoneditor'

const validator = createAjvValidator({ schema, schemaDefinitions })
Resolving Remote Schemas

If you want Ajv to load remote schemas through its loadSchema function, use the async validator builder like this:

javascript
import { createAjvValidatorAsync } from 'svelte-jsoneditor'

const validator = await createAjvValidatorAsync({
  schema: {
    $ref: "/schema.json",
  },
  ajvOptions: {
    loadSchema: function (uri: string) {
      return fetch(uri).then((response) => response.json());
    },
  },
});

createAjvValidatorAsync resolves only after Ajv has loaded and compiled all referenced schemas, or rejects on errors, e.g. if loadSchema returns a rejected promise.

parser

typescript
parser: JSON = JSON

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. For example:

xml

validationParser

typescript
validationParser: JSONParser = JSON

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. So, when the validationParser can output bigint numbers or other numeric types, the validator must also support that. In tree mode, when parser is not equal to validationParser, the JSON document will be converted before it is passed to the validator via validationParser.parse(parser.stringify(json)).

pathParser

typescript
pathParser: JSONPathParser

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. Alternatively, it is possible to use for example a JSON Pointer notation like /data/2/nested/property or something custom-made. Related helper functions: parseJSONPath and stringifyJSONPath, parseJSONPointer and compileJSONPointer.

maxDocumentSizeTextMode

typescript
maxDocumentSizeTextMode: number

In text mode, JSON documents with a total length greater than maxDocumentSizeTextMode will not be shown. Instead, a warning will be displayed indicating that the browser may crash if it attempts to load the document. The user can then choose to override the warning and open the document anyway, open the document in the lighter tree mode instead, or cancel.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScripteditorjsonsvelte

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架