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 6774759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:49:34+00:00 2026-05-26T15:49:34+00:00

Sorry, I completely neglected to mention that I’m using Python. Let me try this

  • 0

Sorry, I completely neglected to mention that I’m using Python. Let me try this again.

I’m using Python to consume a web service that returns the following JSON:

{
  "results" : [
    {
      "paramName" : "output",
      "dataType" : "GPString",
      "value" : "{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}"
    }
  ],
  "messages" : [

  ]
}

Here are the important snippets from my fetching/parsing code:

import urllib
import httplib2
import json
import simplejson
http = httplib2.Http()

headers, response = http.request(url, 'GET')    

if headers['status'] == "200":

    responseAsJson = simplejson.loads(response)

    print "response = " + repr(responseAsJson)
    results = responseAsJson['results'][0]['value']

Unfortunately, this leaves me with the following value for results (as reported in PyScripter Debugger’s Variables window):

u"{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}"

I don’t know how to then access the address or city keys, for instance.

Can you tell what I’m doing wrong, and how to fix it?

Thanks,
Jamie


Old version of my question (obsolete):

Here’s the JSON I’m parsing:

response = {u'messages': [], u'results': [{u'dataType': u'GPString', u'value': u"{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}", u'paramName': u'output'}]}

I’ve drilled down to this node, and its type is “unicode.” How do I make a dict out of this? I think the fact that it’s unicode is preventing me from creating the dict or accessing its keys, but I’m not sure.

u"{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}"

Thanks,
Jamie

  • 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-05-26T15:49:34+00:00Added an answer on May 26, 2026 at 3:49 pm

    Since your results object looks like a string/unicode version of a dict, you need to eval it. A safe way of doing this (as of Python 2.6) would be to use the ast.literal_eval function:

    results = ast.literal_eval(responseAsJson['results'][0]['value'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me just start out by saying I am completely new to Java web
I remade this post because my title choice was horrible, sorry about that. My
sorry if this is an obvious question, but I am relatively new to python
Hi I am completely new to Java, so sorry if my question may sound
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry, I'm new to SVN and I looked around a little for this. How
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Sorry if this sounds like a really stupid question, but I need to make
I'm still a working on learning RSpec so I'm sorry if completely overlooked something...

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.