MV Reading multiple JSON objects from one file or altering a JSON object's file directly?

I'm trying to make a custom data structure that gets saved based on my input from inside the game. Kind of think of it like Yanfly's GridFreeDoodad's plugin, which I'm sort of using as a reference except without the fancy UI and graphical loading. In short, I'm making a plugin that'll help me toggle a feature that allows me to click an object, drag it to a location, place it, face it a certain direction, and then save that event data to a JSON file to be read when I reopen the game. More or less allowing me to make a custom event placement system that isn't dependent on the 48x48 grid.

I've done something like this before, where I also set up a system where I can click and drag the player to a location, face them in a direction, and then prompt you to warp to another map where you can also click and drag your player, name the warp, and save that data to a data structure I called $dataWarps, allowing for precise warping of the character between named warp points. And that one actually works pretty well, though with my loose understanding of reading and writing files, I feel like it works by the skin of my teeth.

In this instance, I have run into the problem of keeping a catalogue of pretty much every object in every map in a structure called $dataColliders. This object contains a hierarchy that looks like:

Code:
$dataColliders
- _data
-- 0 null
-- 1 Game Map 1
--- mapId: 1
--- mapName: 'Game Map 1'
--- events: [null, event 1, event 2, ...]
-- 2 Game Map 2
-- 3 Game Map 3...

I've had a lot of trouble trial-and-erroring when and where and how I need to load this data, because from my understanding, the $gameMap and event data is actually loaded when you enter the map, which I've pinpointed to Game_Map.prototype.setupEvents; I'm currently exploring how to load the data, but part of that problem is that there's not really a way to load all that data up front. While I technically could just load the data in on a map-by-map basis, it kind of necessitates creating a corresponding JSON file for every map, and so, what if the map ID changes, or some similar thing that makes it so I have to move all that data over to the new map? What if the new map's event IDs are totally different? And in any case, it sort of seems redundant to keep a nigh-identical data structure index when I could just go into $dataMap.events like normal and piggyback off that.

My question is, is there a clean way to say, go into the MapXXXX files, add an object after the event data, and then have the Game_Map.prototype.setupEvents or other initialization function read that second object's data, or even better yet, simply insert the data I need into each event as I go along? Where would I even start doing that? I've read a lot of tutorials about it, but everyone's more concerned with just getting the basic functionality down without imparting a lot of deeper understanding.
I would just load the entire file into $dataColliders at game start, then add functions to DataManager for extracting specific map/event data using IDs.
I would just load the entire file into $dataColliders at game start, then add functions to DataManager for extracting specific map/event data using IDs.

That's sort of what I'm doing. Are you saying that that might just be what I've gotta do? Because I'm not particularly good at this right now, so if that's the case, I might just make it create a corresponding MapCollider1.json, MapCollider2.json, MapCollider3.json, etc. file for each map. Though, I don't know how to script in something that creates a JSON file. I've just been manually creating one whenever I need one and read/writing that.
Oh hang on, so this is data that's being created as you progress in the game rather than data that's already known?

Are you familiar with require("fs"); and the XMLHttpRequest object?
Oh hang on, so this is data that's being created as you progress in the game rather than data that's already known?
It's more like I'm using the game as editing software. My intention is to go into the game, alter the starting positions and other features of each event, and then save that to a JSON that will ship out once the game has been finalized. It's for debugging and development, not something players are meant to do. Making it so the data is saved as the player goes along would be a lot easier than what I'm talking about, I think.
Yeah, you want to look at require fs and XMLHttpRequest, then.

Original thread: https://forums.rpgmakerweb.com/threads/reading-multiple-json-objects-from-one-file-or-altering-a-json-objects-file-directly.146943/