Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 823
preetam Avatar asked Oct 14 '25 04:10

preetam


1 Answers

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.

like image 141
Daniel Roseman Avatar answered Oct 16 '25 17:10

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!