1

Possible Duplicate:
Easy JSON encoding with Python

I want to get a record from database and built it in to json. I know we can do it with json_encode when using PHP. But how can we do it in Python

9
  • if theres something, there is a Library for anything in Python, 'import antigravity' ftw! Commented Oct 14, 2010 at 10:14
  • 5
    "Didn't spend fifteen seconds on Google" needs to be a close reason. Commented Oct 14, 2010 at 10:18
  • If you cant answer, left this question. Why getting irritated?. This site is specifically for Programmers and Google is generally for all the things. Here i can get experts with updates. And I can get multiple views. So if u dont like to answer, leave stackoverflow. Dont make beginner programmers like me out. Commented Oct 14, 2010 at 10:27
  • 'irritated'? No. We're educating you on how to ask a good question. Your question was downvoted for reasons. We're providing the reasons. You can complain that you don't want to learn. In which case, perhaps you should leave StackOverflow. We're not leaving beginners out. We're educating beginners. Step 1. Use Google. Step 2. Read the Python Library. Step 3. Post code that doesn't work. If you can't do that, you're not really a "programmer". Commented Oct 14, 2010 at 11:04
  • 4
    @Rajasekar: I expect that the majority of irritated people, aside from perhaps being a little cranky, feel this way because your question as it stands is answered by typing "python json" into Google search and hitting "I'm feeling lucky". You're not asking a question it takes a programmer to answer and you're displaying a frightening lack of inititative. Your question does not solicit multiple view points from experts. If you are unable to resolve relatively simple problems yourself like this, then perhaps programming and technology in general isn't your ideal vocation. Commented Oct 14, 2010 at 11:15

2 Answers 2

9
# Python 2.6+
import json
result = json.dumps(value)
or
# Python 2.6+
import json
json.dump(value, out_file)

Got if from google first result. http://www.php2python.com/wiki/function.json-encode/

Please do your research before asking simple, searchable questions!

Sign up to request clarification or add additional context in comments.

1 Comment

then the question may be, what json implementation is most stable/featured/available on Python3. Not asking, but isn't that style of hints is welcome?
2

There are several json implementations for Python. I like simplejson because it's, well, simple.

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.