0

I am creating a dashboard for Google Analytics and I want to convert the JSON what is coming from Google Analytics into a python list, but keep getting this error:

Expecting property name: line 1 column 2 (char 1)

Here is the code which should convert it:

results = get_results(service, profile)
data = json.loads(str(results))
return data

Results is equal to:

{u'columnHeaders': [{u'columnType': u'METRIC',
                 u'dataType': u'INTEGER',
                 u'name': u'ga:sessions'}],
u'containsSampledData': False,
u'id': u'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:xxxxxxxx&metrics=ga:sessions&start-date=7daysAgo&end-date=today',
u'itemsPerPage': 1000,
u'kind': u'analytics#gaData',
u'profileInfo': {u'accountId': u'xxxxxxxx',
              u'internalWebPropertyId': u'xxxxxxxx',
              u'profileId': u'xxxxxxxx',
              u'profileName': u'xxxxxxxx',
              u'tableId': u'ga:xxxxxxxx',
              u'webPropertyId': u'UA-xxxxxxxx-1'},
u'query': {u'end-date': u'today',
        u'ids': u'ga:xxxxxxxx',
        u'max-results': 1000,
        u'metrics': [u'ga:sessions'],
        u'start-date': u'7daysAgo',
        u'start-index': 1},
u'rows': [[u'109826']],
u'selfLink': u'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:76270671&metrics=ga:sessions&start-date=7daysAgo&end-date=today',
u'totalResults': 1,
u'totalsForAllResults': {u'ga:sessions': u'109826'}}

I have removed some account details above but hopefully get the picture.

Thanks,

Aaron

5
  • this is not JSON, results might already be a dict Commented Apr 7, 2016 at 13:56
  • What is type of results (do print(type(results)))? Commented Apr 7, 2016 at 13:58
  • What should the list look like? As is clear in your results dict, it is a tree structure, which is generally the case for JSON data. Commented Apr 7, 2016 at 14:01
  • I'm new to Python, and I think I have been getting them mixed up, thanks for all your help! Commented Apr 7, 2016 at 14:08
  • json.loads() returns a python dictionary of the data you retrieved in json format. It isn't a list. Please post your complete traceback and your actual code Commented Apr 7, 2016 at 14:24

1 Answer 1

2

your result doesnt look like a string much more like a python object (dict) (because of the unicode mark before every string) maybe your should try this:

print(type(result))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.