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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:59:37+00:00 2026-05-25T18:59:37+00:00

I have the below JSON returned from a DB. How do I refer to

  • 0

I have the below JSON returned from a DB. How do I refer to the element STOCK without specifying by name? I know I can do NewDataSet.STOCK but this JSON is dynamic.

I have tried NewDataSet[1] but it doesn’t like that. Is there a way to refer to it?

{
    "NewDataSet": {
            "@": {
                "xmlns": "STOCK"
            },
            "STOCK": {
                "STOCK_GROUP": "Default",
                "STOCK_CODE": "qwertyuiop",
                "FEEDER_OR_TRAY_NUMBER": "1",
                "ENABLED": "Enabled",
                "WEIGHT": "1",
                "PRIORITY": "0",
                "STOCK_TYPE": "Paper",
                "STOCK_ID": "1",
                "VALID_FROM": "1900-01-01T00:00:00+00:00",
                "VALID_TO": "1900-01-01T00:00:00+00:00",
                "STOCK_IMAGE": {}
            }
        }
    }

Here is an example of 2 or more rows::

{
    "NewDataSet": {
        "@": {
            "xmlns": "SECURITY_GROUPS"
        },
        "SECURITY_GROUPS": [
            {
                "GROUP_ID": "100",
                "NAME": "Administrators",
                "DESCRIPTION": "Access to all aspects of system"
            },
            {
                "GROUP_ID": "101",
                "NAME": "Operators",
                "DESCRIPTION": "users of device"
            }
        ]
    }
}

I then run this javascript:

$.each(data[0], function(key, value) {
    columnArr.push({"sTitle" : key});
});

$.each(data, function(key, value) {
    var innerArr = [];
    $.each(value, function(innerKey, innerValue) {
        innerArr.push(innerValue);
    });
    alueArr.push(innerArr);
});
  • 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-25T18:59:37+00:00Added an answer on May 25, 2026 at 6:59 pm

    You can iterate over the elements in a associative array like this:

    for (var key in NewDataSet) {
        if (obj.hasOwnProperty(key)) {
            // key holds 'STOCK', obj[key] holds the data you are after
        }
    }
    

    Looking at the data, they kind of suggest what you should actually do is to explicitly retrieve ‘@’ and then check ‘xmlns’ in there to understand what key you should be searching for…

    — edit after your edits it’s clearer that this is what you need

    var tableName = NewDataSet['@'].xmlns;
    var rows = NewDataSet[tableName];
    // enforce array
    if (!rows.hasOwnProperty('length')) { rows = [rows]; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JSON date returned from a MVC page e.g. DateProcessed:\/Date(1258125238090)\/ and
I have the JSON string below : { name:Ruby on Rails Baseball Jersey, price:19.99,
I have below a list of text, it is from a popular online game
I have an issue regarding to auto populating a select dropdown from jQuery/JSON data
I have a JSON response that is formatted from my C# WebMethod using the
I have a JSON multi-level response that I need to deserialize and from the
I have been struggeling all day to read a json file from server and
I have a Coldfusion Webservice that returns json data like below: {rows:[{cell:[43,USA,jon,doe,doe@gmail.com,HR],id:43}, {cell:[44,JAPAN,tanaka,yidi,yidi@aol.com,IT],id:44}], page:1,records:2,total:1}
I have a NSURLConnection that gets data from a JSON web service, and everything
I have the below query, which basically it retrieves the 5 top most books

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.