Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dynamic JSON arrays

Featured Replies

I am building a dynamic database in JSON with a JavaScript HTA. I am stuck on "visualizing" how to traverse the array.

The easiest way I can explain this in something everyone knows is an email program's Inbox folders. You start out with an empty folder, all the new messages go in it. Fine.

Now, the user wants to add a sub-folder, Mark, and sub-folder Work. Fine, I can do that. Building it is easy.

Inbox

---Mark (folder)

---Work (folder)

.....messages in Inbox root not in a sub-folder....

Now the user is going crazy:

Inbox

---Mark (folder)

---Work (folder)

------Accounting (folder)

------Shipping (folder)

---------National (folder)

---------International (folder)

This is all fine if I make the JSON array "hardcoded" from the start so I would know how to access it:

Inbox[1].Work[1].Shipping[0].National[0].Message1

BUT, it was created by the user, so how do I step through the dynamically created JSON database not knowing the names (per se) and the depth of the array?

Essentially, I need a JavaScript database that will traverse the array for me looking for the ID (or whatever tag) I give it:

var message=jsonDB.find("ID","f7df68yfudsaf67fd");

or

var message=jsonDB.find("From","eat@joes.com");

That returns an object pointing to that email message, in which I can do:

message.From="eat@joes.com";

message.To="bugs@bunny.com";

The same issue above also carries over to deleting the email message, deleting entire folders, etc.

var message=jsonDB.delete("ID","87hds732h");

I looked at TaffyDB but what I tried didn't work. It doesn't seem to like nested arrays.

Edited by mritter

  • 3 months later...

I am building a dynamic database in JSON with a JavaScript HTA. I am stuck on "visualizing" how to traverse the array.

The easiest way I can explain this in something everyone knows is an email program's Inbox folders. You start out with an empty folder, all the new messages go in it. Fine.

Now, the user wants to add a sub-folder, Mark, and sub-folder Work. Fine, I can do that. Building it is easy.

Inbox

---Mark (folder)

---Work (folder)

.....messages in Inbox root not in a sub-folder....

Now the user is going crazy:

Inbox

---Mark (folder)

---Work (folder)

------Accounting (folder)

------Shipping (folder)

---------National (folder)

---------International (folder)

This is all fine if I make the JSON array "hardcoded" from the start so I would know how to access it:

Inbox[1].Work[1].Shipping[0].National[0].Message1

BUT, it was created by the user, so how do I step through the dynamically created JSON database not knowing the names (per se) and the depth of the array?

Essentially, I need a JavaScript database that will traverse the array for me looking for the ID (or whatever tag) I give it:

var message=jsonDB.find("ID","f7df68yfudsaf67fd");

or

var message=jsonDB.find("From","eat@joes.com");

That returns an object pointing to that email message, in which I can do:

message.From="eat@joes.com";

message.To="bugs@bunny.com";

The same issue above also carries over to deleting the email message, deleting entire folders, etc.

var message=jsonDB.delete("ID","87hds732h");

I looked at TaffyDB but what I tried didn't work. It doesn't seem to like nested arrays.

Maybe you could try the solution from here, then you would not need to know the propery names:

http://efreedom.com/Question/1-2824299/Select-First-Property-Unknown-Name-First-Item-Array-JSON

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.