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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:23:35+00:00 2026-05-20T23:23:35+00:00

I’m currently working on a project using javascript and python with Jquery Datatables plugin

  • 0

I’m currently working on a project using javascript and python with Jquery Datatables plugin and Django. My problem is that I am trying to create a dictionary in Python which I then wish to perform a json.dumps(dictionary) in order to send it across to the JQuery.

The conversion is performed and I can using a debugger see the data in the JQuery/Javascript code however it does not populate my table the reason being that the JSON is malformed. This I believe is due to the way the Dictionary in python code is created. I know I’m doing something wrong at this step. All the examples I’ve seen show a hard coded dictionary I need to create my dictionary dynamically. Here is the code I’m using in python. If anyone knows what I’m doing wrong please let me know this is driving me insane. This is the latest permutation of the dictionary code:-

    dictionary = {}
    array = []
    status = 'OFF'
    for item in self.scanResults:
        if item[6]:
            status = 'ON'
        else:
            status = 'OFF'

        array.append( {'MAC_ADDRESS':item['mac_addr'],
                    'IP_ADDRESS':item['ip_addr'],
                    'NAME':item['name'],
                    'OS':item['os'],
                    'OS_VERSION':item['os_version'],
                    'WORKGROUP':'--',
                    'STATUS':status
        })
    dictionary = dict({'aaData': array})    

The JSON on the JQuery side should be in this format:-

{"aaData": [[..,..,..,..,],[..,..,..,..]]}

Cheers for any help you can provide

Chris

EDIT:

Additional information. Sorry for not including it earlier.
I’m encoding it the following way :-

return HttpResponse(simplejson.dumps(response_dict), mimetype=’application/javascript’)

The screen dump of results is:-

{“aaData”: [{“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.2”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:10:e3:42:16:35”, “OS”: “Linux”, “NAME”: “Machine_One”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.3”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:a3:41:16:31”, “OS”: “Linux”, “NAME”: “Machine_Two”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.4”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:b3:43:16:32”, “OS”: “Linux”, “NAME”: “Machine_Three”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.5”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:c3:44:16:33”, “OS”: “Linux”, “NAME”: “Machine_Four”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.6”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:d3:45:16:34”, “OS”: “Linux”, “NAME”: “Machine_Five”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.7”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:e3:46:16:37”, “OS”: “Linux”, “NAME”: “Machine_Six”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.8”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:f3:47:16:38”, “OS”: “Linux”, “NAME”: “Machine_Seven”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.9”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:g3:48:16:38”, “OS”: “Linux”, “NAME”: “Machine_Eight”}, {“STATUS”: “ON”, “WORKGROUP”: “–“, “IP_ADDRESS”: “192.168.0.10”, “OS_VERSION”: “8.04”, “MAC_ADDRESS”: “00:19:h3:49:16:41”, “OS”: “Linux”, “NAME”: “Machine_Nine”}]}

The actual epected results would be :-

{“aaData”:[[“ON”,”–“,”192.168.0.6”, “8.04”, “00:19:d3:45:16:34”, “Linux”, “Machine_Five”],
[“ON”,”–“,”192.168.0.6”, “8.04”, “00:19:d3:45:16:34”, “Linux”, “Machine_Five”]]}
Just to give you an idea.

I’m using jQuery DataTables plugin for this. I beleive the problem is malformed dictionary ie: my fault. I’m new to python and have tried numerous permutations of dictionaries and have discovered 10+ ways not to do it I just need a hint to that elusive right way.

Cheers again

Chris

SOLVED:

I’ve solved the issue by passing back from the server an array of arrays (list of lists) if you prefer and parsing them on the client side due to the fixed size of the lists this is not causing a performance issue. I shall look more closely at this at a later date and post up a better fix or more elegant solution.

  • 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-20T23:23:36+00:00Added an answer on May 20, 2026 at 11:23 pm

    The code in your question does not contain the key bit we need to see – how you are serialising your dictionary into a string. If you are just doing str(dictionary) then that will not work, you need to encoded it using simplejson. You can install this library with easy_install, or if you’re using Python 2.6+ then it’s included as json.

    To encode a Python object as a JSON string simple use json.dumps(dictionary).

    You say that your Javascript code is expecting an object containing nested lists, but your Python code seems to be generating an object like {"aaData": [{..:.., ..:..},{..:.., ..:..}]}, i.e. a dictionary, inside a list, inside a dictionary. If the problem isn’t with how you’re encoding the JSON string can be clearer about the object you’re expecting?

    EDIT

    As Ignacio Vazquez-Abrams states in your Python code you’re adding dictionaries to the list then expecting them to have magically transformed into lists when they’re encoded as JSON. You either need to convert your Javascript to work with the data you are sending at the moment, or replace your current Python code with something similar to what Ignacio suggests.

    I would suggest the first of these options as it is easy to get things wrong when using a list to represent a structure and you’ll end up using the wrong value because you got the indexes wrong. If you keep it as a dictionary/object then you can access things by name and you avoid that problem.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

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.