Jack Haymes
Jack Haymes

Reputation: 13

Parsing a Salesforce JSON object with Python

I'm new to Salesforce and Python and having a bit of trouble figuring this out, any help would be greatly appreciated.

from simple_salesforce import Salesforce
import requests
import csv
import json
import pdb

sf = Salesforce(
   username='[email protected]', password='XXXXXX', security_token='security_token')

accDetails = sf.query("SELECT Name FROM Account")
#print(accDetails)


try:
    #pdb.set_trace()
    decoded = json.loads(accDetails)

    # Pretty printing of json-formatted string
    print json.dumps(decoded, sort_keys=True, indent=4)

    print "JSON decoded: ", decoded['two']['list'][1]['item']

except (ValueError, KeyError, TypeError):
    print "JSON format error"

it's throwing the "JSON format error" error. I'm sure it's someting simple I'm doing incorrectly, as I said I'm very new to this.

Upvotes: 0

Views: 1164

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599856

Assuming you are using the Salesforce class from here, it does not return JSON; it returns an already-decoded dict. There is no need to call json.loads on it.

Upvotes: 1

Related Questions