Is JSON library part of python by default or is it external package. Is simplejson a different package than Json

StackOverflow https://stackoverflow.com/questions/22760509

سؤال

Well, 2 straight forward questions. I am trying to use json with django. I tried to use shell and do import json No errors here. But when I try to use json_dumps() or just dumps() I am getting

NameError: name 'json_dumps' is not defined

Apparently my json import din't work despite having no error.

Also, a few bonus questions I had during this are:

  1. simplejson and json are same or different packages.
  2. Which one is native to python
  3. which one is recommended under what scenarios.
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top