Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python is converting double quotes to single quotes in new variable

Tags:

python

I'm trying to save a variable with double quotes in python, because I need to pass the double quoted JSON to a template and single quotes wont work with what I'm doing. So I set the variable in python to:

json = {
  "auth": {
    "key": "auth-code-here"
  },
  "template_id": "id-here",
  "redirect_url": "url-here",
}

But immediate in python, it's saved as

{'redirect_url': 'url-here', 'template_id': 'id-here', 'auth': {'key': 'auth-code-here'}}

Is there a way I can save it as double quoted? Or will I need to process this in a django template to replace the single quotes for double quotes?

Thanks!

like image 232
Brenden Avatar asked Jun 09 '11 14:06

Brenden


1 Answers

You should use a JSON module to do that. To Python, double- and single-quotes are interchangeable.

Python has JSON abilities built in.

like image 96
Chris Cooper Avatar answered Sep 27 '22 22:09

Chris Cooper