"Proper" JSON structure for an array of data intended for populating a dropdown menu

I am currently in a "cart before the horse" situation as I do not have an actual JSON source yet, due to waiting on some access permissions.

However, in the meantime, I have created a JSON structure that resembles the data I am collecting. I will eventually have control over the PHP script generating this JSON, so it might change if needed.

My main objective is to parse this JSON and populate three dropdowns dynamically with the information from each level. However, I haven't started writing the JavaScript for this functionality yet.

My question revolves around whether this JSON format is suitable for my goal of filling the three dropdowns in sequence:

(For example, upon loading the page, only the first dropdown should display group options. Upon selecting a group, the second dropdown should load Fiscal Year options related to that group, followed by Quarter options upon selection. The dropdowns should reset if the group is changed.)

HTML Dropdowns (Not generated dynamically yet):

<div class="form-group">
    <label>Choose Group</label>
    <select id="Portfolio" class="form-control">
        <option value="value1">Group1</option>
        <option value="value2">Group2</option>
        <option value="value3">Group3</option>
    </select>
</div>

<div class="form-group">
    <label>Choose FY</label>
    <select id="FiscalYear" class="form-control">
        <option value="value1">FY19</option>
        <option value="value2">FY20</option>
        <option value="value3">FY21</option>
    </select>
</div>

<label>Choose Quarter</label>
<select id="Quarter" class="form-control">
    <option value="value1">Q1</option>
    <option value="value2">Q2</option>
    <option value="value3">Q3</option>
    <option value="value4">Q4</option>
</select>

Proposed JSON Format:

{
    "FY19": [{
        "q1": [{
            "Group1": [{
                "Rate1": 91.4,
                "Rate2": 10.5,
                "Rate3": 97.5,
                "Rate4": 24,
                "Rate5": 97.5,
                "Rate6": 14.03,
                "Rate7": 74,
                "Rate8": 20,
                "Rate9": 69
            }]
        }]
    }],
    "FY20": [{
        "q2": [{
            "Group2": [{
                "Rate1": 91.4,
                "Rate2": 10.5,
                "Rate3": 97.5,
                "Rate4": 24,
                "Rate5": 97.5,
                "Rate6": 14.03,
                "Rate7": 74,
                "Rate8": 20,
                "Rate9": 69
            }]
        }]
    }],
    "FY21": [{
        "q3": [{
            "Group3": [{
                "Rate1": 91.4,
                "Rate2": 10.5,
                "Rate3": 97.5,
                "Rate4": 24,
                "Rate5": 97.5,
                "Rate6": 14.03,
                "Rate7": 74,
                "Rate8": 20,
                "Rate9": 69
            }]
        }]
    }]
}

Answer №1

To improve readability and organization, consider structuring each key-value pair in your Groups as an object.

{
"FY19": [
  {
    "q1": [
      {
        "group1": [
          {
            "Rate1": 90
          }]
       }]
   }],
 //"FY20": [...and so forth]
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a connectivity issue with the MongoDB server

While I wrote my server IP on the mongoose connection string, I am unable to insert data into MongoDB. How can I resolve this issue? var express = require("express"); var app = express(); var mongoose = require('mongoose'); mongoose.connect(&ap ...

extracting an attribute from a class's search functionality

Let's consider the following HTML structure: <div id="container"> <div> <div class="main" data-id="thisID"> </div> </div> </div> If I want to retrieve the value inside the data-id attribute ...

What is the best way to update the contents of an array, transform it, and then store it in a single cell within a database

I am currently working on manipulating the values in the $_FILES array and I have a query regarding inserting these modified values into a single cell in the database as an array. After making changes to each object within the array, I would like to store ...

Guide to exporting a JSON array asynchronously following an HTTP request in Node.js

I am facing a challenge with asynchronously exporting a variable. My goal is to access the apiData in another file. Currently, I am exporting an empty array for clear reasons. How can I achieve this asynchronously and retrieve the JSON data? var exp ...

D3 Tree and Leaflet Map Unintentional Disruption

I have set up a Leaflet Map in one div and a collapsible tree using d3 in another div (based on this Fiddle): https://i.sstatic.net/zAC2m.png The Leaflet Map (located in the right div) loads a GeoJSON, while the D3 tree (in the left div) loads correspondi ...

Does the color of the item change as it gets older?

How can I smoothly transition a color as it ages using a dynamic time scale? I want to calculate the age based on the difference in time rather than triggering an animation after an event. I aim for a seamless gradient transition between two colors over a ...

how can JavaScript be used to retrieve an object based on a condition from an array of objects and an ArrayList

My JavaScript challenge involves working with an array of objects called arrobj and a list called prgList. The goal is to extract the names from arrobj based on the programs listed in prgList. If the program exists in arrobj, it should be displayed accor ...

Is there a way to organize data by month using Chart Js?

I have been working with Chart.js and encountered an issue while trying to organize the dates fetched from my MongoDB to display them according to the respective month. In the provided image, the line does not seem to align with the correct month index. I ...

Displaying the array of structures

Why is my printList() function only outputting the last element added to the array by addInfo()? Is there a mistake in how elements are being added to the array? #include <stdio.h> #include <stdlib.h> //structure Location typedef struct Loc ...

Set a Value to a Specific Node in a Multidimensional Array Using JavaScript

Trying to update an element within a JSON object with a new value (text/object/array). I have a swap function that takes in the JSON object, an array with indexes to retrieve the element, and the value to replace it with. Currently using eval, which some c ...

Is it possible to accurately measure the width of elements down to the partial pixel level?

This dilemma has been causing me frustration for quite some time. My goal is to achieve a simple task - float li elements in a ul container and give them a hover effect. Here's the code snippet: Everything seems to be in order, with all CSS reset, dis ...

The use of JSON in AJAX animations can hinder the transfer of data via PHP

I'm currently working on a form for submitting email messages. I've added an ajax animation, but for some reason, the data isn't being passed to php. I'm not sure what the issue could be. Any help would be greatly appreciated. Thank you ...

The Datepicker in MUI - React is unable to recognize the `renderInput` prop on a DOM element

I've been experimenting with the MUI version 5 DatePicker component. I followed the example provided in the MUI documentation's codesandbox demo. Here is how my component looks: const MonthPicker: FC = () => { const [value, setValue] = Rea ...

Add unique styles to a jQuery-included HTML document

I'm attempting to use jQuery to load an HTML page into the main body of another page. Specifically, I have a div called sidebar_menu positioned in the middle of the page, and I am loading content at the bottom using jQuery. $("#sidebar_menu").load(" ...

TroubControls not functioning properly in ThreeJS when using import map

Looking for assistance in setting up a simple ThreeJs with OrbitControls for pan and zoom. I successfully got it working with an older version (128), but encountering issues with the newer r168. In my example, I am attempting to directly embed the JavaScr ...

Display the URL created in the DIV

I have a JavaScript function that constructs a URL using form inputs and allows users to preview it in a DIV named "preview" before opening the URL in a new window via a submit button. While everything is working as expected, I am looking for a way to mod ...

The jQuery method .index() can be quite perplexing when it comes to

http://learn.jquery.com/using-jquery-core/understanding-index/ After reading the article linked above, I found myself struggling to grasp the reasoning behind why the index number changes in a peculiar manner when an argument is used with .index(). Consi ...

Turning an array into JSON using PHP

I'm encountering some difficulty in parsing the data as I attempt to change the shape of the array into JSON format. Here is an example of the current array structure: Array ( [id] => 1 [fisrt_name] => raul [last_name] => gon ...

Tips for converting a JSON array into an SQL Table

Can anyone help me with a problem I'm facing? I'm struggling to figure out how to extract information from a JSON objects list. In my dataset, there are 3 items (objects) labeled [item1, item2, item3]. I am trying to retrieve the name of each i ...

Storing Various Text Inputs in MySQL Database

Within my HTML document, I have the following code snippet to collect input in a specific format: Stuff1,Stuff2,Stuff3,Stuff4 <form action="process_form.php" method="post"> <form> Part 1: <input type="text" name="p1" /><br ...