v1.2.2

API Reference: Instance Members

Last updated


This page lists the properties and methods available on a JSONEditor instance after construction.

Properties


body, editor, and children are assigned asynchronously after data loading and are not ready when the constructor returns — see Core Concepts.
MemberTypeDescription
jsongetter → stringSerializes the current data to a 4-space-indented JSON string; keyless root children are dropped — see Serialization
typegetter → stringRoot node type; the current implementation always returns "object", even after importing an array
childrenJSONEditorNode[]Top-level child nodes
bodyHTMLElementEditor root DOM element (with the pd-json-editor class)
editorHTMLElementNode container DOM element (<section>)
buttonArrayInitialized to []; unused by the current implementation

Methods


MethodReturnsDescription
import(data)Promise<void>Imports new data (Object / File / URL string) and re-renders with render(true) — see Data Loading
export()voidDownloads NanoJSON-{timestamp}.json; a single keyless root child is still written (unlike the json getter)
reset()voidEquivalent to import({}); leaves the editor with no nodes
enable()voidLeaves read-only mode; removes disabled across the rendered DOM
disable()voidEnters read-only mode; adds disabled across the rendered DOM — see Read-Only Mode
render(isUpdate = false)voidRe-renders all top-level nodes; triggers Lifecycle.update only when isUpdate === true and the initial render has completed
insert()voidAppends an empty root-level node (type "string") and re-renders without triggering Lifecycle.update

Example


editor.type is read after the initial render, then import() replaces the data and updated prints editor.json:
  1. <section id="editor"></section>
  2. <script>
  3. const editor = new JSONEditor({
  4. id: "editor",
  5. fill: false,
  6. json: { name: "NanoJSON" },
  7. when: {
  8. rendered: () => {
  9. console.log("type:", editor.type);
  10. editor.import({ name: "NanoJSON", version: "1.2.1", tags: ["json"] });
  11. },
  12. updated: () => console.log(editor.json),
  13. },
  14. });
  15. </script>
Live preview · @pardnchiu/nanojson@1.2.2

Further Reading


中文