Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:15:37+00:00 2026-06-01T22:15:37+00:00

I have a huge JSON file. It’s not in the correct structure and I

  • 0

I have a huge JSON file. It’s not in the correct structure and I have no control over the structure. It is data coming from a group of routers based on timestamp. I’m trying to create an object structure that combines all the info for a given router into a router object with timestamp etc. as arrays. @quodlibetor was a big help getting me close to this. I also want to automatically name the properties of the object from the name of the name val pairs in the json.

My aim is to autoname the properties from the names in the json file and to restructure it into an object that looks like this (I’m open to suggestions on the structure this just seemed the most organized way to do it).

This is the structure I want:

    {
        "Router": [
            {
                "routerName": "RouterID1",
                "TimeStamp": [
                    "2012/01/01 06:00:00",
                    "2013/01/01 06:00:00",
                    "2014/01/01 06:00:00"
                ],
                "OutputBITS": [
                    "23235",
                    "29903",
                    "22103"
                ],
                "InputBITS": [
                    "23235",
                    "29903",
                    "22103"
                ]
            }
        ]
    }

Although trying to create that structure I’m getting close but no deal:

{
    "RouterID1": {
        "timeStamp": [
            {
                "timeStamp": "2012/01/01 06:00:00"
            },
            {
                "timeStamp": "2013/01/01 06:00:00"
            },
            {
                "timeStamp": "2014/01/01 06:00:00"
            }
        ],
        "OutputBITS": [
            {
                "OutputBITS": "23235"
            },
            {
                "OutputBITS": "23235"
            },
            {
                "OutputBITS": "23235"
            }
        ],
        "InputBITS": [
            {
                "InputBITS": "29903"
            },
            {
                "InputBITS": "29903"
            },
            {
                "InputBITS": "29903"
            }
        ]
    }
}

ORIGINAL JSON:

json = [
         {
              "Router": "RouterID1",
              "TimeStamp": "2012/01/01 06:00:00",
              "OutputBITS": "23235",
              "InputBITS":  "29903"
         },   
          {
              "Router": "RouterID1",
              "TimeStamp": "2013/01/01 06:00:00",
              "OutputBITS": "23235",
              "InputBITS":  "29903"
         },   
          {
              "Router": "RouterID1",
              "TimeStamp": "2014/01/01 06:00:00",
              "OutputBITS": "23235",
              "InputBITS":  "29903"
         },
         {
              "Router": "RouterID3",
              "TimeStamp": "2012/01/01 06:05:00",
              "OutputBITS": "21235",
              "InputBITS":  "22103"
         },
         {
             "Router": "RouterID3",
             "TimeStamp": "2012/01/01 06:05:00",
             "OutputBITS": "21235",
             "InputBITS":  "22103"
        },
        {
            "Router": "RouterID4",
            "TimeStamp": "2012/01/01 06:05:00",
            "OutputBITS": "21235",
            "InputBITS":  "22103"
       },
       {
           "Router": "RouterID4",
           "TimeStamp": "2012/01/01 06:05:00",
           "OutputBITS": "21235",
           "InputBITS":  "22103"
      }
      ];  

CODE:

    //  Create routers object    
    var routers = {};


       for (var i=0;i<json.length;i++){
        var router_name = json[i].Router;
        router_name = (router_name.replace(/-/g, ""));  //take hyphen out or router name

        if (!routers[router_name]){
            // add properties to the router object thanks to @@quodlibetor

            // instead of using timeStamp is something like json[i] or json.[name] or some
            // way to reference each json property and not have to type it in?

            routers[router_name] = { timeStamp : [], OutputBITS : [], InputBITS : [] };
        }

                routers[router_name].timeStamp.push({
                    timeStamp : json[i].TimeStamp
                }); 
                 routers[router_name].OutputBITS.push({
                     OutputBITS : json[i].OutputBITS
                }); 
                routers[router_name].InputBITS.push({
                    InputBITS : json[i].InputBITS
                });  
    }; 

    console.log(routers);
    });
     </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:15:39+00:00Added an answer on June 1, 2026 at 10:15 pm

    Here is the code you need:

    var router = {router: []}, i, j, k, l, inArray, routerName, thisRouter;
    
    for(i=0,j=json.length;i<j;++i) {
        inArray = false;
    
        routerName = json[i].Router;
    
        for(k=0,l=router.router.length;k<l;++k) {
            if(router.router[k].name === routerName) {
                inArray = true; --k; l = k;
            }
        }
    
        if(inArray === true) {
            router.router[k].TimeStamp.push(json[i].TimeStamp);
            router.router[k].OutputBITS.push(json[i].OutputBITS);
            router.router[k].InputBITS.push(json[i].InputBITS);
        } else {
            thisRouter = {name: routerName, TimeStamp: [json[i].TimeStamp], OutputBITS: [json[i].OutputBITS], InputBITS: [json[i].InputBITS]};
    
            router.router.push(thisRouter);
        }
    }
    
    console.log(router);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge JSON file to parse in my Android app. I suppose
I have huge amont of geographic data represented in simple object structure consisting only
I have this huge JSON file. Currently the way I am using it is:
I have a huge (400MB) initial_data.json file. Django's eating up all my memory trying
I have huge data which is static. I need to save it within the
I have a huge access mdb file which contains a single table with 20-30
I have a huge chunk, so large that I can't manually edit the file
I don't know whether this question makes sense or not. I have huge amount
I have huge text file of such format: aaa bbb 1 aaa ccc 2
I have a list of products coming from a repository. Simple enough. Now I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.