-1
import json

I'm trying to create a simple json error message to return if I receive a 404 error during the course of my program, but it isn't working as I anticipated.

error_data = '{"can_post": "error", "website": "error"}'
print json.dumps(error_data)

gives me:

"{\"can_post\": \"error\", \"website\": \"error\"}"

what am I doing wrong? I expected:

{"can_post": "error", "website": "error"}

I realize I could do this:

error_data = '{"can_post": "error", "website": "error"}'
print json.dumps(error_data)

Which works.

0

1 Answer 1

1

You are feeding json.dumps a string. It should be an object:

error_data = {"can_post": "error", "website": "error"}
print json.dumps(error_data)
Sign up to request clarification or add additional context in comments.

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.