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 7194117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:18:24+00:00 2026-05-28T20:18:24+00:00

I receive an array from a server which contains objects and association tables. So

  • 0

I receive an array from a server which contains objects and association tables. So for example, I have this JSON result from the server:

var myEvent = {
   "Event":{
      "SessionTags":[
         {
            "SessionID":1,
            "TagID":x
         },
         {
            "SessionID":2,
            "TagID":x
         },
         {
            "SessionID":2,
            "TagID":y
         },
         {
            "SessionID":3,
            "TagID":z
         }
      ],
      "Sessions":[
         {
            "ID":1,
            "Name":"Advanced Tips",
         },
         {
            "ID":2,
            "Name":"Best Practices"
         },
         {
            "ID":3,
            "Name":"Code Fun"
         },
      "Tags":[
         {
            "ID":x,
            "Name":"AJAX"
         },
         {
            "ID":y,
            "Name":"Android"
         },
         {
            "ID":z,
            "Name":"ASP.NET"
         },
      ]
   }
}

Notice the “SessionTags” object that is used as an association table. How do I add the right tag object in the session tag so I end up with this:

var myNewEvent = {
   "Event":{
      "Sessions":[
         {
            "ID":1,
            "Name":"Advanced Tips",
            "Tags":[
              {
               "ID":x,
               "Name":"AJAX"
              }
            ]
         },
         {
            "ID":2,
            "Name":"Best Practices",
            "Tags":[
              {
               "ID":x,
               "Name":"AJAX"
              },
              {
               "ID":y,
               "Name":"Android"
              }
            ]
         },
         {
            "ID":3,
            "Name":"Code Fun",
            "Tags":[
              {
               "ID":z,
               "Name":"ASP.NET"
              }
            ]
         }
   }
}
  • 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-05-28T20:18:25+00:00Added an answer on May 28, 2026 at 8:18 pm

    Try this:

    var getTagName = function(tagId){
        var t = myEvent["Event"]["Tags"];
        for (var i in t); {
            if (t[i].ID == tagId) {
                return t[i].Name;
            }
        }
    };
    
    var getTags = function(sessionId){
        var s = myEvent["Event"]["SessionTags"];
        var tags = [];
        for (var i in s) {
            if (s[i]["SessionID"] == sessionId) {
                var tagName = getTagName(s[i]["TagID"]);
                tags.push({"ID": sessionId, "Name": tagName});
            }
        }
        return tags;
    };
    
    var addSessionTags = function(){
        var s = myEvent["Event"]["Sessions"];
        for (var i in s) {
            var currentSession = s[i];
            currentSession.Tags = getTags(currentSession.ID);
        }
    };
    
    addSessionTags();
    
    delete myEvent.Event.Tags;
    delete myEvent.Event.SessionTags;
    

    I had to clean up your data slightly (IDs of x,y,z didn’t refer to any variables, and you also have some extra commas and a missing closing bracket) to get it to be workable for the example:

    var myEvent = {
       "Event":{
          "SessionTags":[
             {
                "SessionID":1,
                "TagID":"x"
             },
             {
                "SessionID":2,
                "TagID":"x"
             },
             {
                "SessionID":2,
                "TagID":"y"
             },
             {
                "SessionID":3,
                "TagID":"z"
             }
          ],
          "Sessions":[
             {
                "ID":1,
                "Name":"Advanced Tips",
             },
             {
                "ID":2,
                "Name":"Best Practices"
             },
             {
                "ID":3,
                "Name":"Code Fun"
             }
         ],
          "Tags":[
             {
                "ID":"x",
                "Name":"AJAX"
             },
             {
                "ID":"y",
                "Name":"Android"
             },
             {
                "ID":"z",
                "Name":"ASP.NET"
             }
          ]
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a low level caching mechanism which receives a json array from a
I have an array of bytes that I receive from an external entity. It
I currently develop a server application which has to receive serialized data from clients,
Server at location A I have a Service hosted which will process array received(ByRef)
I have to send a byte array (encoded photo) from my PHP client to
I have to send the audio data in byte array obtain by recording from
I have a 3rd party server which has a classic ASP page which takes
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I have a server on which I keep track of some data. When I
I've got this form, which generates an array as output, and I want to

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.