function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robert JakubovRobert Jakubov 

getting JSON_PARSER_ERROR....Unexpected character

Hi there,

I am getting the following error when call the REST API (modify Account information) from Python:
<type 'list'>: [{u'errorCode': u'JSON_PARSER_ERROR', u'message': u"Unexpected character ('B' (code 66)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]"}]

I have the following JSON data input:
 args={
              'BillingCity' : 'NY'
       }

and a header with the access Authorization token (not posted here).

Can anyone please help?

thanks
Rob
Amit Chaudhary 8Amit Chaudhary 8
your JSON should be like below
{
"args":{
              "BillingCity" : "NY"
       }
}
And apex class should be like below
public class JSON2Apex {

	public class Args {
		public String BillingCity;
	}

	public Args args;

	
	public static JSON2Apex parse(String json) {
		return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
	}
	
	static testMethod void testParse() {
		String json = '{'+
		'\"args\":{'+
		'              \"BillingCity\" : \"NY\"'+
		'       }'+
		'}';
		JSON2Apex obj = parse(json);
		System.assert(obj != null);
	}
}
Please try below link for json to apex:-

https://json2apex.herokuapp.com/

Please let us know if this will help you

Thanks
Amit Chaudhary
Robert JakubovRobert Jakubov
But how should I use this from Python?
the way I use the JSON input data is as following?
args={
        "BillingCity":"NY"
}

and then pass to the request
req = requests.patch(

            'https://na34.salesforce.com/services/data/v34.0/sobjects/Account/00161000003L6Tx',

             headers=headers2,

            data=json

    )

    response = req.json()
Robert JakubovRobert Jakubov
sorry typo:


data=args 
 
Amit Chaudhary 8Amit Chaudhary 8
= is not a valid char in json i guess