or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdeditor-core.mdindex.mdmode-management.mdpreview-mode.mdschema-validation.mdtext-operations.mdtransform-operations.mdtree-operations.md
tile.json

editor-core.mddocs/

0

# Editor Core

1

2

Main JSONEditor constructor and core data manipulation methods for creating editors and managing JSON content.

3

4

## Capabilities

5

6

### JSONEditor Constructor

7

8

Creates a new JSONEditor instance with specified configuration.

9

10

```javascript { .api }

11

/**

12

* Create a JSONEditor instance

13

* @param container - HTML DIV element where the editor will be created

14

* @param options - Configuration options object (optional)

15

* @param json - Initial JSON data to load (optional)

16

*/

17

constructor(container: HTMLElement, options?: JSONEditorOptions, json?: any);

18

```

19

20

**Usage Example:**

21

22

```javascript

23

import JSONEditor from "jsoneditor";

24

25

const container = document.getElementById("jsoneditor");

26

const options = {

27

mode: "tree",

28

search: true,

29

history: true

30

};

31

const initialData = { message: "Hello World" };

32

33

const editor = new JSONEditor(container, options, initialData);

34

```

35

36

### Get JSON Data

37

38

Retrieves the current JSON data from the editor.

39

40

```javascript { .api }

41

/**

42

* Get JSON data from the editor

43

* @returns The current JSON data

44

* @throws Error when editor contains invalid JSON (in code/text/preview modes)

45

*/

46

get(): any;

47

```

48

49

### Set JSON Data

50

51

Sets JSON data in the editor, resetting the editor state.

52

53

```javascript { .api }

54

/**

55

* Set JSON data in the editor

56

* @param json - JSON data to display

57

*/

58

set(json: any): void;

59

```

60

61

### Get Text Data

62

63

Retrieves the current data as a JSON string.

64

65

```javascript { .api }

66

/**

67

* Get JSON data as string

68

* @returns Contents as JSON string

69

*/

70

getText(): string;

71

```

72

73

### Set Text Data

74

75

Sets data from a JSON string.

76

77

```javascript { .api }

78

/**

79

* Set text data in the editor

80

* @param jsonString - JSON string to parse and display

81

* @throws Error when jsonString is invalid JSON (in tree/view/form modes)

82

*/

83

setText(jsonString: string): void;

84

```

85

86

### Update JSON Data

87

88

Replaces JSON data while maintaining editor state (expanded nodes, search, selection) in tree/form/view modes.

89

90

```javascript { .api }

91

/**

92

* Replace JSON data when the new data contains changes

93

* @param json - New JSON data to display

94

*/

95

update(json: any): void;

96

```

97

98

### Update Text Data

99

100

Replaces text data while maintaining editor state in tree/form/view modes.

101

102

```javascript { .api }

103

/**

104

* Replace text data when the new data contains changes

105

* @param jsonString - New JSON string to parse and display

106

* @throws Error when jsonString is invalid JSON (in tree/view/form modes)

107

*/

108

updateText(jsonString: string): void;

109

```

110

111

### Destroy Editor

112

113

Cleans up the editor and removes all DOM elements, event listeners, and web workers.

114

115

```javascript { .api }

116

/**

117

* Destroy the editor and clean up resources

118

*/

119

destroy(): void;

120

```

121

122

### Focus Editor

123

124

Sets focus to the JSONEditor.

125

126

```javascript { .api }

127

/**

128

* Set focus to the JSONEditor

129

*/

130

focus(): void;

131

```

132

133

### Refresh Editor

134

135

Forces the editor to refresh the user interface and update all rendered HTML.

136

137

```javascript { .api }

138

/**

139

* Force refresh of the user interface

140

* Useful when using onClassName with external dependencies

141

*/

142

refresh(): void;

143

```

144

145

### Root Node Name Management

146

147

Manage the field name for the root node in tree-based modes.

148

149

```javascript { .api }

150

/**

151

* Set field name for the root node

152

* @param name - Field name, or undefined to remove current name

153

*/

154

setName(name?: string): void;

155

156

/**

157

* Get the current field name for the root node

158

* @returns Current field name or undefined if not set

159

*/

160

getName(): string | undefined;

161

```

162

163

**Usage Example:**

164

165

```javascript

166

// Set a name for the root node

167

editor.setName("userData");

168

169

// Get the current name

170

const currentName = editor.getName(); // "userData"

171

172

// Remove the name

173

editor.setName();

174

```