Skip to content
acegoal07 edited this page Aug 29, 2022 · 10 revisions

json-editor Documentation

This is wiki contains a breakdown of the package and how to use each function

Installation

npm i @acegoal07@json-editor

Available tools

  • editFile - Creates an editor instance for the specified file
  • createFile - Creates a json file
  • createFileEditor - Creates a new file and passes it with the editor attached already
  • deleteFile - Deletes the specified json file
  • copyFile - Duplicates the file you specify
  • moveFile - Moves the file from the old location to the new location
  • renameFile - Renames the specified file to the new provided name
  • readFile - Returns the data from the specified file
  • readAllFiles - Retunes a map filed with all the data from the files

Example

const json = require("@acegoal07/json-editor");

json.createFile("display.json");
// Create a new json file

let file = json.editFile("display.json", {autosave: true});
// file content = {}

file.set("Hello", "world!");
file.set("toggle", true);
file.set("data", []);
// {
//   "Hello": "world!",
//   "toggle": true,
//   "data": []
// }

console.log(file.get("Hello"))
// log => world!

file.push("data", "test");
file.push("data", "test2")
file.unshift("data", "test3");
file.set("items", {"world": "world!"});
file.unset("Hello");
// {
//   "data": [
//       "test3",
//       "test",
//       "test2"
//   ],
//   "items": {
//       "world": "world!"
//   }
// }

file.emptyArray("data");
file.emptyObject("items");
// {"data": [], "items": {}}

file.empty()
// {}

json.copyFile("display.json", "json/display.json");
json.deleteFile("display.json");
// Deletes the specified json file

json.renameFile("json/display.json", "show.json");
// Changes the name of the specified file
Clone this wiki locally