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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:18:36+00:00 2026-06-17T00:18:36+00:00

Firstly I am a Total jquery/js newbee! Then I Have a long json like

  • 0

Firstly I am a Total jquery/js newbee!
Then I Have a long json like this:

[
{
    "rulesrev": 74,
    "macaddr": "",
    "lat": "3543.03133N",
    "ip": "10.128.113.180",
    "clientname": "D-06-29",
    "relay0mask": "-1",
    "relay1stat": "-1",
    "clientid": 542,
    "bldname": "D_valiasr_zartosht",
    "uptime": "",
    "current": "",
    "temperature": "",
    "softver": "",
    "relay0stat": "0",
    "volume": "100",
    "hardver": " ",
    "relay1mask": "-1",
    "pic": "",
    "comment": " p",
    "lon": "05124.48299E",
    "rtt": "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)",
    "bldaddr": ""
},
{
    "rulesrev": 74,
    "macaddr": "00:10:f3:22:30:08,00:10:f3:22:30:09",
    "lat": "3537.41356N",
    "ip": "10.19.64.63",
    "clientname": "M-19-013",
    "relay0mask": "-1",
    "relay1stat": "-1",
    "clientid": 494,
    "bldname": "tarebar_m19",
    "uptime": "19d 20:05:12",
    "current": "",
    "temperature": "",
    "softver": "",
    "relay0stat": "0",
    "volume": "100",
    "hardver": " n",
    "relay1mask": "-1",
    "pic": "",
    "comment": " ",
    "lon": "05122.94431E",
    "rtt": "2012/08/25 09:19:25.0 (load=0.05) (mem=0.17)",
    "bldaddr": ""
}
]  

and i want to convert it to a Jquery DataTable readable array which should be like this:

"aaData": [
            /* Reduced data set */
            [ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X" ],
            [ "Trident", "Internet Explorer 5.0", "Win 95+", 5, "C" ],
            [ "Trident", "Internet Explorer 5.5", "Win 95+", 5.5, "A" ],
            [ "Trident", "Internet Explorer 6.0", "Win 98+", 6, "A" ],
            [ "Trident", "Internet Explorer 7.0", "Win XP SP2+", 7, "A" ],
            [ "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", 1.8, "A" ],
            [ "Gecko", "Firefox 2", "Win 98+ / OSX.2+", 1.8, "A" ],
            [ "Gecko", "Firefox 3", "Win 2k+ / OSX.3+", 1.9, "A" ],
            [ "Webkit", "Safari 1.2", "OSX.3", 125.5, "A" ],
            [ "Webkit", "Safari 1.3", "OSX.3", 312.8, "A" ],
            [ "Webkit", "Safari 2.0", "OSX.4+", 419.3, "A" ],
        [ "Webkit", "Safari 3.0", "OSX.4+", 522.1, "A" ]
        ],
        "aoColumns": [
            { "sTitle": "Engine" },
        { "sTitle": "Browser" },
            { "sTitle": "Platform" }
]  

what should i do?
I can not find any post here or elsewhere to describe something like this
can anyone help?
EDIT
the second array is just a structure i saw in datatables
example. and i want to change my json to a structure like the second array
EDIT:
in my json the first part of each data will make the table column header that will go to the bottom of second array structure and the second part which is the values goes to the second array structure top part. and finally it should looks like this:

      "aaData": [
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""],
[ 74, "", "3543.03133N", "10.128.113.180", "D-06-29", "-1", "-1", 542, "D_valiasr_zartosht", "", "", "", "", "0", "100", "", "-1", "", " p", "05124.48299E", "2012/08/15 23:20:55.0 (load=0.05) (mem=0.11)", ""]
    ],        "aoColumns": [
{ "sTitle": "macaddr" },
{ "sTitle": "lat" },
{ "sTitle": "ip" },
{ "sTitle": "clientname" },
{ "sTitle": "relay0mask" },
{ "sTitle": "relay0stat" },
{ "sTitle": "relay1stat" },
{ "sTitle": "clientid" },
{ "sTitle": "bldname" },
{ "sTitle": "uptime" },
{ "sTitle": "current" },
{ "sTitle": "temperature" },
{ "sTitle": "softver" },
{ "sTitle": "volume" },
{ "sTitle": "hardver" },
{ "sTitle": "relay1mask" },
{ "sTitle": "pic" },
{ "sTitle": "comment" },
{ "sTitle": "lon" },
{ "sTitle": "rtt" },
{ "sTitle": "bldaddr" },
 ] 
 ]
  • 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-17T00:18:38+00:00Added an answer on June 17, 2026 at 12:18 am

    There’s no magic way. You have to iterate through your original object and create an object in the format expected by datatable.

    Suppose you want three columns on your table

    rulesrev,macaddr,lat

    You could use the following code to generate the data in the format required by datatables http://jsfiddle.net/vZVUc/

    var originalJson = [{...}]; // Your JSON blob
    
    // You can't rely on the order of iteration of properties in your JSON object,
    // so you have to specify which fields you want
    var columns = ["rulesrev", "macaddr", "lat"];
    
    // If you don't care about the order of properties, you can generate columns 
    // using the following
    var columns = [];
    for (var propName in originalJson[0]) {
      columns.push(propName);
    }
    
    var dataTableObj = {
       aaData: [],
       aoColumns: []
    };
    
    // Stuff the aoColumns array
    for (var i=0; i < columns.length; i++) {
        dataTableObj.aoColumns.push({sTitle: columns[i]})
    }
    
    // Stuff the aaData array
    for (var i=0; i < originalJson.length; i++) {
        var row = originalJson[i];
        var dataTableRow = [];
        for (var j=0; j < columns.length; j++) {
            dataTableRow.push(row[columns[j]]);
        }
        dataTableObj.aaData.push(dataTableRow);
    }
    
    // Now you can pass it to your datatable
    $('#example').dataTable( dataTableObj );
    

    If you’re adventurous you can use Array.map (supported in later browsers only, but easy to create a shim for). http://jsfiddle.net/vZVUc/1/

    // You can't rely on the order of iteration of properties in your JSON object,
    // so you have to specify which fields you want
    var columns = ["rulesrev", "macaddr", "lat"];
    
    var dataTableObj = {
       aaData: originalJson.map(function(row) {
          return columns.map(function(col){
              return row[col];
          })
       }) ,
       aoColumns: columns.map(function(col){
          return {sTitle: col}
       });
    }; 
    

    This isn’t tested, so there are probably bugs, but it should teach you how to do it. See http://jsfiddle.net/vZVUc/1/ and http://jsfiddle.net/vZVUc/ for examples

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly I have a class signature that looks like this: internal class JobStore :
Firstly, I wrote my customized setter for an NSString* like this: - (void)setDateString:(NSString *)newDateString
Firstly, this is going to sound like homework, but it ain't. Just a problem
This is a two part question; firstly, does anyone out there have some insight
Firstly, I have migrated my CVS repository into SVN repository. I checked out this
Firstly I would say that I have read this post however I still have
Firstly I have tried to re create this within a JSfiddle but unable to,
Firstly I have to say that I have been like 2 weeks researching on
Firstly, let me set out what I'd like to do. Assume I have three
firstly I would like to say sorry if this is a repost, onto the

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.