preetam
preetam

Reputation: 1587

Is the json library a part of Python by default? Are the simplejson and json packages the same?

I am trying to use JSON with Django.

When I execute import json in the shell, I receive no errors. However, when I try to use json_dumps() or just dumps() I get the following error:

NameError: name 'json_dumps' is not defined

Apparently my json import didn't work despite having no errors. How can I get it to work?

Additionally:

  1. Are simplejson and json the same packages?
  2. Which one is native to Python?
  3. Which one is recommended under what scenarios?

Upvotes: 4

Views: 8255

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599470

Your error doesn't have anything to do with your question. This is a simple matter of Python namespacing: the function is json.dumps not json_dumps.

However, json has been a part of the standard library since 2.5. simplejson is a separate library. Unless you know you need it, you should use json.

Upvotes: 15

Related Questions