-2

This is the dictionary that I have given for the json.dumps in my views.py

{1: {'status': u'up', 'count': 8}, 2: {'status': u'down', 'count': 12}}

I have to use this in my javascript. I have tried the following way but not working for me.

var mydata = json.loads({{indexdata}});

can anyone please help me with this?

5
  • 1
    And what template language is this? Is this Flask, Django, something else? Commented Oct 25, 2014 at 12:36
  • And Javascript doesn't have a json module; that's Python code only. Commented Oct 25, 2014 at 12:36
  • var mydata = {{indexdata}}; ? Commented Oct 25, 2014 at 12:36
  • @Martijn Pieters, that is Django template language and I have no idea what to write in Javascript, that is the reason why I need help Commented Oct 25, 2014 at 12:39
  • JSON is essentially a JavaScript Object, why would you need to 'parse' it? Commented Oct 25, 2014 at 12:54

2 Answers 2

0

Try this:

var mydata = {{indexdata}};
Sign up to request clarification or add additional context in comments.

Comments

0

java script interprets things like you've posted as an object. you don't need any conversion.

var myObj = {a : { b : 5 }}

is a valid js object

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.