RedditPP Mascot

RedditPP

r/electronjs • … • u/ducklord

How can I store and recall the values of nested objects with INI using their names?

UPDATE: Found a way to side-step the problem - look at the end for more details.

Howdy fine folks of ElectronJS!

I'm trying to save and load to an INI file a bunch of configuration strings for a mini-app I'm trying to build. Since I'm a noob (I only have basic experience with AutoHotKey), I've tried following INI's official information... and failed.

To clarify:

I **do** have an INI with some data I need, and I **did** manage to load it and save it. My problem, though, is with setting up new objects/arrays within the existing one. Here's an example.

id = 00001 filename = Old One theme= blue backupsFrequency= ""

[content] title = "" sections = ""

[content.outline] section[]={"id":"1","title":"Test title", "notes":"Here be notes!","research":"No research yet!"} section[]={"id":"2","title":"Another test title", "notes":"MOAR notes!","research":"Research Kaput!"}

Is it possible to somehow craft such an INI file so that I can "recall" values from it by using something like:

console.log(INIfile.content.outline.section[0].title);

?!?

Thanks in advance for any help and suggestions.

## UPDATE: The way I've dealt with the issue So, I've wasted many-many hours trying to understand how INI stores and recalls values. Theoretically, with INI, when you save an object which contains a lot of config values with **stringify**, it turns into a text string and then stored to a file. When you load it into a variable using **parse** afterwards, it should turn back into a proper object. For me, though, it didn't, and some stuff insisted on appearing as strings.

Now, there's obviously something **I** am missing, but here's my beef as a newcomer to the programming world: documentation sucks. It might be easy to understand when you've got some concepts pinned down, but not when you're trying to understand the basic entry-level stuffs.

So, as a prime example of that, the official INI's documentation talks about how to store multi-level data in an INI, how to load and save objects, and offers an example of how to store items into an array...

...but doesn't offer a single example of storing and recalling a multi-level array. At least, not that I saw. Same goes for the dozens of tutorials available online.

So, instead of busting my head more, trying to grok how it works, I've simply saved everything as JSON into a file, which I'm now happily loading and saving from my custom app. As a typical JSON data structure I have as many levels of nested data as I wish, and can recall the values within without any fuss, just the way I wanted, by using "data level names", like "file.section.entry[0].data".

Hurrah.

I hope this ends up helping anyone who finds themselves stuck in the same place I was.

And if this is somehow wrong and I **should** be using INIs instead of directly storing and loading JSON from a file, for one or the other reason, if you'd be so kind, do tell why.

— 0