As long as the file is inside your project folder (config file, i.e.) you can load it synchronously requiring it directly in NodeJS.

var test = require('./array.json');

And then the content will be loaded into your variable in the next executed sentence.

You can try to console.log it, and it will print:

[ { name: 'c', content: '3', _prototype: 'item' },
  { name: 'd', content: '4', _prototype: 'item' } ]

Right exactly in the order that the file had.

Answer from jesusbotella on Stack Overflow
🌐
Restack
restack.io › p › nested-json-structure-examples-answer-node-read-json-file-into-array
Node Read Json File Into Array | Restackio
To load JSON data in Node.js, you can utilize the built-in fs module along with JSON.parse to read and parse JSON files effectively. This method allows you to read JSON files into an array, making it easy to manipulate the data as needed.
🌐
Quora
quora.com › How-do-I-convert-JSON-file-to-Javascript-Array
How to convert JSON file to Javascript Array - Quora
Answer (1 of 8): A JavaScript object or value is converted to a JSON string using the JSON.stringify() method, with the option to replace values if a replacer function or replacer array is given, or to include only the specified attributes otherwise.
🌐
Example Code
example-code.com › nodejs › json_array_load_and_parse.asp
Node.js Loading and Parsing a JSON Array
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • ...
🌐
Futurestud.io
futurestud.io › tutorials › node-js-read-a-json-file
Node.js — Read a JSON File
Node.js provides the fs module to read files from the local hard disk. Use the Fs.readFile to read the content of a given file. Related to a JSON file, you’ll then have the JSON content as a string.
🌐
TutorialKart
tutorialkart.com › nodejs › nodejs-parse-json
Node.js Parse JSON - Parsing JSON Data or JSON File - TutorialKart
November 30, 2020 - Node.js Parse JSON – For parsing JSON data in Node.js, we can use JSON.parse() function of JavaScript Engine. In this tutorial, we will learn how to parse given JSON string using JSON.parse() function, with example programs.
🌐
Attacomsian
attacomsian.com › blog › nodejs-read-write-json-files
How to read and write JSON files in Node.js
October 1, 2022 - Node.js provides built-in modules that make it easy to work with JSON data. In this article, you'll learn to: Read JSON files from the disk.
🌐
Temboo
temboo.com › nodejs › parsing-json
Parsing JSON in Node.js
To do this, you'll use the following square bracket syntax for specifying the items array, then the first item in that array (at index 0), and finally the snippet object within the first item in the array: 7 To finish up, the title and description ...
Find elsewhere
🌐
2ality
2ality.com › 2025 › 08 › javascript-json-processing-files.html
[Web dev for beginners] JSON and processing files in Node.js
For SUBCMD_ADD, we read the file, push a string to the array in property .item and write the data back to storage.
🌐
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
Typed Arrays Typed Methods Typed Reference Array Buffers DataViews JS Atomics JS DOM Navigation · DOM Navigation DOM Nodes DOM Collections DOM Node Lists JS Windows · JS Window JS Screen JS Location JS History JS Navigator JS Popup Alert JS Timing JS Cookies JS Web APIs · Web APIs Intro Fetch API Geolocation API Web History API Web Pointer API Web Storage API Validation API Web Worker API JS AJAX · AJAX Intro AJAX XMLHttp AJAX Request AJAX Response AJAX XML File AJAX PHP AJAX ASP AJAX Database AJAX Applications AJAX Examples JS JSON
🌐
HeyNode
heynode.com › tutorial › readwrite-json-files-nodejs
Read/Write JSON Files with Node.js | HeyNode
By the end of this tutorial you should be able to work with JSON files using Node’s built-in fs module. Say you have a customer.json file saved to disk that holds a record for a customer in your store. As part of your store app, you want to access the customer’s address, and then update the order count after an order is placed. In this tutorial, we are going to look at how to read and write to our customer.json file.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-read-and-write-json-file-using-node-js
How to read and write JSON file using Node ? | GeeksforGeeks
January 7, 2025 - A straightforward way to read a JSON file in a Node JS file is by using the `require()` method to include it.
🌐
Geshan
geshan.com.np › blog › 2024 › 10 › nodejs-read-json-file
How to Read a JSON File Using Node.js
October 30, 2024 - This JSON data represents an array of objects, each of which corresponds to a billionaire and contains attributes like rank, net worth, name, gender, category, country of origin, and more. The native fs module in Node.js provides a straightforward way to interact with the file system. You’ll explore two methods for reading ...
🌐
Stack Overflow
stackoverflow.com › questions › 73400619 › convert-data-from-json-file-to-javascript-array
Convert data from JSON file to JavaScript Array? - Stack Overflow
var JS_Obj = '{"prop_1":"val_1", "prop_2":"val_2", "prop_3" : "val_3"}'; up.innerHTML = "JSON string - '" + JS_Obj + "'"; var down = document.getElementById("GFG_DOWN"); function myGFG() { var obj = eval('(' + JS_Obj + ')'); var res = []; for(var i in obj) res.push(obj[i]); down.innerHTML = "Array of values - [" + res + "]"; } ` Work with these approaches, It will solve your problem if you're working in HTML... But, If you're working with frameworks then you will have to use the fs.readFile() and other file system algorithms in node.js.
🌐
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?
November 22, 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!