Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:07:42+00:00 2026-06-06T15:07:42+00:00

I’ve read the simplejson docs and don’t understand why it sometimes returns a json

  • 0

I’ve read the simplejson docs and don’t understand why it sometimes returns a json object with single quotes (which php can’t understand) and other times returns an escaped sequence of double quotes (also not recognized in php). I could probably do regex on the output string as a bandaid, but I’d rather understand the source of the problem.

Example:

INPUT: (The starting data in python)

print stories

{‘text’: ‘HIV/AIDS One day, \r\nThen we took her home and we called for the meeting and told the villagers that we should take care of her and give her the good care that she need in her lifetime before she depart.’, ‘id’: 1215L}

And as a sanity check – the json object looks normal before cherrypy gets a hold of it:

print simplejson.dumps( stories )

[{“text”: “youth to youth empowerment… yada yada yada…”, “id”: 12828}, {“text”: “women … yada yada yada…”, “id”: 12828}]

...
import simplejson
return simplejson.dumps( stories )

[some obscure magic happens with cherrypy…]
Here’s the part in cherrypy that passes the json to a browser:

@cherrypy.expose
def browse_stories(self):
    stories = test_org_match.browse_org_story_matches()
    cherrypy.response.headers['Content-Type'] = 'application/json'
    return json.dumps( stories )

Output (what I see in a browser calling this object via cherrypy):

“[{\”text\”: \”POVERTY We decided to steal the vegetables. There was nothing we could do. We had stayed for two days without food and these third day we could not keep up. We had to eat something or we would die. We started slowly towards the shamba and took as much as we could we went home and cooked and ate and we felt better.\”, \”id\”: 33109}, {\”text\”: \”Boda Bado They simply on transport basis people can move round using bada-boda transport to save time \r\n It relay helped the rural people deep in the village to transport themeselves to the other ears using motorcycle bicycle. \”, \”id\”: 35931}]”

(The enclosed text is different but this happens with any one of the random text snippets it is pulling)

NOTE: I believe the other case where simplejson returns an object with single quotes everywhere is because I passed str(dictionary) instead of the actual dictionary. Of course, php breaks when you serve up single-quoted json. But the “free” escaping baffles me – and is happening inside cherrypy I think.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:07:43+00:00Added an answer on June 6, 2026 at 3:07 pm

    I figured it out. My code uses json.dumps() and then it uses json.dumps again – so the extra escape characters is json treating this as a string and not as a dictionary object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.