0

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.

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I see. How could I then write 'accDetails' to a file(csv or txt) in a formatted structure? I can't find any straightforward solutions anywhere.
You can use json.dumps, like you are doing. You just don't need to call json.loads first.

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.