var data = []

function Client(date, contact) {
      this.date = date
      this.contact = contact
}

clients = new Array();

for (i = 0; i < 4; i++) {
    clients.push(new Client("2018-08-0" + i, i))
}

for (i = 0; i < clients.length; i++) {
    var dict = {}
    dict['Date'] = clients[i].date
    dict['Contact'] = clients[i].contact
    data[i] = dict
}

console.log(data)
Answer from clucle on Stack Overflow
Discussions

appending to json file in javascript - Stack Overflow
I have a json file, employees.json, that I would like to append data to this object. More on stackoverflow.com
🌐 stackoverflow.com
Appending to JSON object using JavaScript - Stack Overflow
A JavaScript Object Literal is a comma-separated list of name/value pairs wrapped by a pair of curly braces. To append the property name of encampment name with a value of Valley Forge to the bottom of the stack, simply add the property name after the JSON object with a dot syntax. Then specify the value. (See 'Append data... More on stackoverflow.com
🌐 stackoverflow.com
October 10, 2010
How to add data to a JSON file in JavaScript?
The specifics can vary slightly ... your JavaScript code is running (Node.js server-side versus client-side in a browser). On a Node.js server, you have the filesystem (fs) module available to read from and write to files directly. Here’s how you can add data to a JSON ... More on designgurus.io
🌐 designgurus.io
1
10
June 25, 2024
How do I append to an array inside a json file in node?
If it's stored as JSON, you'd read the JSON in, parse it to JavaScript structures using JSON.parse, push the new messages to the JSON, reserialize it back to JSON, then re-write to to disk. This is quite inefficient though. It would be better to use a database. More on reddit.com
🌐 r/learnjavascript
14
4
December 26, 2022
🌐
Educative
educative.io › answers › how-to-add-data-to-a-json-file-in-javascript
How to add data to a JSON file in JavaScript
{ "users": [ { "name": "John Doe", ... "Bob Johnson", "email": "bob.johnson@example.com" } ] } ... Line 1: Import the fs module for reading and writing into the file....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-how-to-add-an-element-to-a-json-object
How to Add an Element to a JSON Object using JavaScript? | GeeksforGeeks
August 27, 2024 - This article will allow your hand through different ways of coming up with an array of object literals in a loop in JavaScript. Here are different app ... Storing HTML input data into JSON format using JavaScript can be useful in various web development scenarios such as form submissions, data processing, and AJAX requests.
🌐
Reddit
reddit.com › r/learnjavascript › how do i append to an array inside a json file in node?
r/learnjavascript on Reddit: How do I append to an array inside a json file in node?
December 26, 2022 -

I’m working on a chat client and server to learn about API’s and now I need to write the messages submitted by users into the master chat log (a json file with a messages array inside of it). I have been searching for different approaches and they all error out somehow. I’m using node and express for routing if that helps.

tldr; how should one append an object to an array inside a json file using node.

edit: I’ve taken carcigenocate’s advice. I open the file, make the changes in memory, then write to the file and reload it to reflect changes. I am still open to improvements on this design!

Find elsewhere
🌐
Reddit
reddit.com › r/javascript › how to append json object to another json object within $.each loop?
r/javascript on Reddit: How to append JSON object to another JSON object within $.each loop?
March 24, 2017 -

I'm using the Webix framework and I'm trying to save information from a datatable to my server. To do that I'm trying to send all of the information in one big JSON string, but I don't know how to append it to a single variable.

    var grabSelected = grida.getSelectedId(true);
    var record = {};

    $.each(grabSelected, function(index, value) {

        record = grida.getItem(value);

    });

It just returns the last item selected, but I'm trying to get all of them. What am I missing?

🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Append an object to an existing JSON file - JavaScript - The freeCodeCamp Forum
April 18, 2024 - I’m relatively new to JS. I am working on a simple webpage which gets an input from user and manipulates it, and finally returns it as an object. What I want is, to append my output objects to my existing .json file, ea…
🌐
GitHub
github.com › jaxgeller › append-json-file
GitHub - jaxgeller/append-json-file: Append to a json file
var myJson = { name: { first: 'Jackson', last: 'Geller' } } // My file contains {dob: '9/27/1994'} var myFile = 'data.json' // Call -- creates file if it doesn't exist and appends appendjson(myJson, myFile, function() { console.log('done') }) /* output -- data.json { dob: '9/27/1994, name: { first: 'Jackson', last: 'Geller' } } */ npm install appendjson --save ·
Starred by 4 users
Forked by 3 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Quora
quora.com › I-want-to-add-a-new-JSON-object-to-the-already-existing-JSON-Array-What-are-some-suggestions
I want to add a new JSON object to the already existing JSON Array. What are some suggestions? - Quora
Answer (1 of 5): Simply use push method of Arrays. [code]var data = [ { name: "Pawan" }, { name: "Goku" }, { name: "Naruto" } ]; var obj = { name: "Light" }; data.push(obj); console.log(data); /* 0:{name:"Pawan"} 1:{name: "Goku"} 2:{name: "Naruto"} ...
🌐
Reddit
reddit.com › r/javascript › append a json file correclty
r/javascript on Reddit: Append a JSON file correclty
May 21, 2018 -

Hello.

I try to write on a JSON file, but this is what I got :

https://hastebin.com/lilomarede.json

As you can see, the id5 is complelty out of the JSON file.

I tried to use bizarre stuff like this (my actual code):

https://hastebin.com/olehohomoy.js

var punJson = "," + (punJson[punId] = { message: punMessage });

wich punID and punMessage are both values I get just before this little piece of code.

I tried to do

var punJson = "," + (punJson[punId] = { message: punJson[punMessage] });

Obviously, this dosen't work.

I got the error

TypeError : Cannot set property 'id5' of undefined

Any ideas ?

🌐
GeeksforGeeks
geeksforgeeks.org › node.js › how-to-add-data-in-json-file-using-node-js
How to Add Data in JSON File using Node.js ? - GeeksforGeeks
July 23, 2025 - It is one of the easiest ways to ... with Node.js, refer ... To add data in JSON file using the node js we will be using the fs module in node js....
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-add-an-element-to-a-json-object-using-javascript
How to add an element to a JSON object using JavaScript?
February 16, 2023 - Original JSON object: { members: { host: 'hostName', viewers: { userName1: 'userData1', userName2: 'userData2' } } } Adding an element using bracket notation: JSON object after adding property: { members: { host: 'hostName', viewers: { userName1: 'userData1', userName2: 'userData2', userName3: 'userData3' } } } Dot notation is cleaner and more readable when property names are valid JavaScript identifiers.
🌐
Quora
quora.com › How-do-you-add-elements-to-a-JSON-Array
How to add elements to a JSON Array - Quora
Answer (1 of 3): Here’s how you add elements to a JSON array—let’s break it down like you’re sitting around a table with a laptop, trying to figure this out. So, first off, JSON arrays are those square-bracket lists of stuff, right? Like `["apple", "banana"]`. To add something, you ...
🌐
Stack Overflow
stackoverflow.com › questions › 42339742 › how-to-append-json-object-by-using-javascript
jquery - how to append JSON object by using javascript - Stack Overflow
February 20, 2017 - var data = JSON.parse('{"John":{"name":"John","age":30,"city":"New York"},"Jeff":{"name":"Jeff","age":32,"city":"New Jersey"}}'); // append data["Billy"] = JSON.parse('{"name":"Billy","age":64,"city":"Liverpool"}');