How to save JSON data locally (on the machine)?

Active3 hr before
Viewed126 times

6 Answers


Stack Overflow help chat , GitLab launches Collective on Stack Overflow , Meta Stack Overflow ,Thanks for contributing an answer to Stack Overflow!

Once you have your JSON string (Im assuming you know how to get it because if not that's a different question altogether) you can save it using this function:

function saveText(text, filename) {
   var a = document.createElement('a');
   a.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
   a.setAttribute('download', filename);

Call it:

var obj = {
   a: "Hello",
   b: "World"
saveText(JSON.stringify(obj), "filename.json");
load more v

I am using the following link to create a tree like structure: LINK,I used the following link for the same:,I want that whatever changes that happens to the id = "tt" could be retrieved in the form of JSON and store on my local machine. ,I want that whenever the user clicks this save button then he could store this tree structure produced as JSON data on his/her local machine. I want this as this tree is editable. How can I do this?

load more v

I am using the following link to create a tree like structure: LINK, javascript - Phonegap plug-in: the fastest way to transfer JSON data locally , javascript - Save canvas locally in IE ,I used the following link for the same:


Server-side storage: On someone else’s computer (often times one that is in a data warehouse), in a database. Good for storing sensitive information.,Server-side storage Storage on the server,Come up with a few examples of when you think data would be stored server-side vs client-side.,Describe a situation where you would use localStorage instead of server-side storage.

   "commonName": "Swiss Cheese Plant",
   "classification": "Monstera",
   "family": "Araceae",
   "maxHeightInFeet": 30,
   "flower": true,
   "scientificName": "Monstera Deliciosa"

We have an employee.json file in a directory, within the same directory we have a js file, in which we want to import the content of the json file.,Note − While the first function is better suited for node environment, the second function only works in the web environment because the fetch API is only accessible in the web environment.,After running any of the above using require or fetch function, the console output is as follows −,We can use any of the two ways to access the json file −


"Employees": [{
      "userId": "ravjy",
      "jobTitleName": "Developer",
      "firstName": "Ran",
      "lastName": "Vijay",
      "preferredFullName": "Ran Vijay",
      "employeeCode": "H9",
      "region": "DL",
      "phoneNumber": "34567689",
      "emailAddress": ""
      "userId": "mrvjy",
      "jobTitleName": "Developer",
      "firstName": "Murli",
      "lastName": "Vijay",
      "preferredFullName": "Murli Vijay",
      "employeeCode": "A2",
      "region": "MU",
      "phoneNumber": "6543565",
      "emailAddress": ""
load more v

GATE Computer Science Notes,Writing code in comment? Please use, generate link and share the link here.,Object: It is a set of name or value pairs inserted between {} (curly braces). The keys must be strings and should be unique and multiple key and value pairs are separated by a, (comma). Syntax:  ,Note: string, number, boolean, null are simple data types or primitives data types whereas object and array are referred as complex data types. 

  1. String: JSON strings must be written in double quotes like C-language there are various special characters(Escape Characters) in JSON that you can use in strings such as \ (backslash), / (forward slash), b (backspace), n (new line), r (carriage return), t (horizontal tab) etc. 
   "name": "Vivek"

   "city": "Delhi\/India"

here\ / is used
for Escape Character / (forward slash).
load more v

Other "undefined-undefined" queries related to "How to save JSON data locally (on the machine)?"