Adding New Lines in JSON local Storage


var Observable = require("FuseJS/Observable");
var Storage = require("FuseJS/Storage");

var note_Json = ("note_Json.json");
var savedData = Observable("Loading...");
var note = Observable("");
    function(content) {
        // body...
        var data = JSON.parse(content);
        savedData.value = "Last saved: " + data.note;
    function(error) {
        // body...
        savedData.value = "Can't find any notes saved";


function saveData() {
    // body...
    var storeObj = {note: note.value};
    Storage.write(note_Json, JSON.stringify(storeObj));
    savedData.value = note.value;

module.exports = {
    saveData : saveData,
    savedData : savedData,
    note : note,

this is my code to save a text to a json file. What if I wanted to save new lines to this file. e.g

first text saved was


and later when the user enters Jerry it should append “Jerry” to the JSON file. e.g



Hey there! I would suggest instead of trying to save multiple lines to the file, you serialize/deserialize a JSON object, and write that instead. Then you can for example have an array of names (in this case) that you can modify like any other array, and you don’t have to worry about details like reading/writing lines in the file specifically.

For JSON serialization/deserialization, check out JSON.stringify() and JSON.parse() respectively :slight_smile:

Thank you so much. Thanks for the Help budy. I hope this helps someone else soon. Thanks again

No problem!