Another - Expecting 'STRING', '}', got 'undefined' - json

I have a json string created by
let jsonString = "{ \"AjaxBookGenieParams\": " + JSON.stringify(ajaxBookGenieParams) + " }";
I have a problem with a web service call not liking the string. I get:
500 Internal Server Server Error - missing value for parameter: ajaxBookGenieParams.
When I use JSONLint it gives me the error:
Expecting 'STRING', '}', got 'undefined'
Where might I have gone wrong?
Thanks
Abbott
{ \"AjaxBookGenieParams\":{
\"AgeCandidates\":[],
\"AgeItemToDelete\":{
\"ISBN\":\"\",
\"ProductId\":0,
\"ImageUrl\":\"\",
\"Title\":\"\",
\"Price\":0,
\"Quantity\":0,
\"AgeId\":0},
\"AllocatedBooks\":[]},
\"BookGenieParams\":{
\"AllocatedQuantity\":0,
\"AllocatedSubTotal\":0,
\"AllocatedTitles\":0,
\"AllocationBudget\":200,
\"BooksPerTitle\":5,
\"CustomerGuid\":\"\",
\"CustomerId\":0,
\"DefaultBooksPerTitle\":5,
\"MinimumBudget\":200,
\"MoveToCartSubTotal\":0,
\"MoveToCartCount\":0,
\"ReDisplayBreak\":10,
\"SelectedCategories\":[],
\"UserBooksPerTitle\":0},
\"Data\":\"\",
\"ProductFilterParams\":{
\"RootNodes\":[
{\"Id\":50,
\"Name\":\"Ages\",
\"GroupType\":\"ages\",
\"NodeCategories\":[
{\"Id\":38,\"Name\":\"Ages 0 to 2\",\"Count\":54,\"Selected\":\"off\",\"Description\":\"\",\"GroupCats\":[]},
{\"Id\":34,\"Name\":\"Ages 3 to 5\",\"Count\":536,\"Selected\":\"off\",\"Description\":\"\",\"GroupCats\":[]},
{\"Id\":35,\"Name\":\"Ages 6 to 8\",\"Count\":471,\"Selected\":\"off\",\"Description\":\"\",\"GroupCats\":[]},
{\"Id\":37,\"Name\":\"Ages 9 to 12\",\"Count\":1126,\"Selected\":\"off\",\"Description\":\"\",\"GroupCats\":[]},
{\"Id\":36,\"Name\":\"Young Adult\",\"Count\":803,\"Selected\":\"off\",\"Description\":\"\",\"GroupCats\":[]}],
\"Description\":\"Books By Age\",
\"ToolTip\":\"\",
\"Selected\":\"off\",
\"__expanded__\":false}],
\"FilterGuid\":\"\",
\"AgeRange\":{\"Min\":1,
\"Max\":18,\"From\":3,
\"FromInit\":3,
\"To\":12,
\"ToInit\":12},
\"SelectedAges\":[],
\"FilterCategories\":{},
\"ResetFilter\":\"false\"},
\"Request\":\"StartAllocationToCart\"}
}

Why are you building a JSON string by yourself in the first place?
const jsonString = JSON.stringify({
AjaxBookGenieParams: ajaxBookGenieParams,
});

Related

JSON Data is Not Valid

I am getting "JSON Data is Not Valid" error on this Json and i couldn't find what is wrong with it.When I put it in something like a JSON Validator it says
Error: Parse error on line 66: ... "InfoStr": "[{" BankEftCode
":" 00
----------------------^ Expecting 'EOF', '}', ':', ',', ']', got 'undefined'
PS: I put 1234s and aaaa's on names and numbers for privacy so don't worry about them.
{"Header":{
"CallerId":"0060030000",
"RequestId":"10213",
"Status":"SUCCESS",
"ErrorCode":null,
"ErrorMessage":null
},"Body":{
"ComplaintSource":"aaa",
"BankEftCodeIssuer":"12345",
"BankEftCodeAcquirer":"12345",
"EntryUserName":"aaa",
"BankComplaintNo":"aaa",
"ComplaintTimestamp":"1234",
"CustomerIdType":"aaa",
"CustomerIdValue":"1234",
"CustomerName":"aaa",
"CustomerLastName":"1234",
"CustomerCompanyTitle":"",
"IsVIP":false,
"CustomerSegment":"aaa aaa",
"CustomerMobilePhone":"1234",
"CustomerIBAN":"1234567890",
"CustomerAccountNo":"1234",
"CustomerEmail":"",
"ComplaintStatus":"",
"ComplaintStatusStep":"",
"ComplaintStatusDetail":"",
"ComplaintCategory":"C1",
"ComplaintMainTopic":"C1.1",
"ComplaintSubTopic":"C1.1.3",
"ComplaintDate":"2022-05-24T11:28:00+03:00",
"ComplaintExplanation":"aaa",
"ComplaintAmount":8670.0,
"ComplaintCurrency":"TRY",
"ReconciliationAmount":0.0,
"ReconciliationCurrency":"TRY",
"ComplaintCardNo":"1234",
"ComplaintMaskedCardNo":"1224",
"ComplaintEncryptedCardNumber":"aaaa",
"RelatedComplaintNo":"0.0",
"TransactionAmount":8670.0,
"TransactionCurrency":"TRY",
"TransactionTimestamp":"12345676",
"TerminalId":"PT6172",
"TerminalLocation":"aaa",
"TransactionDate":"2022-05-23T11:44:00+03:00",
"TransactionRRNNo":"",
"TransactionAuthorizationNo":"",
"TransactionSTANNo":"",
"TransactionTAMRefNo":"aaaaa",
"TransactionCardNo":"12345",
"TransactionMaskedCardNo":"123456789",
"TransactionCardBrand":"M",
"TransactionCardType":"D",
"TransactionHashCardNo":"wertyuıop",
"TransactionTCKN":"123456789",
"TransactionYKN":"",
"TransactionMobilePhoneNumber":"123456789",
"Comment":"",
"PaymentAgent":"",
"PaymentAgentNo":"",
"PaymentSubscriptionNo":"",
"InfoStr":"[{"BankEftCode":"1234567890","TaskId":"12345","RequestUser":"aaa aaa","ResponseUser":"aaa01","RequestTimestamp":"1234567890","ResponseTimestamp":"134567","RequestComment":"aaaa","ResponseComment":"aaa",
"InfoElements":[{"Key":"AtmCashDifferenceCurrency","Value":null,"Type":null},
{"Key":"AtmCashSurplus","Value":"0","Type":null}
]
}]",
"F_TicketProcessType":"",
"NF_TicketProcessType":"",
"AtmResolveCode":"",
"SLADueDatetime":"2022-05-27T09:49:35.966",
"BankSLADueDatetime":"2022-05-25T12:36:22",
"IsInfoRequested":false,
"IssuerSLASatisfied":true,
"AcquirerSLASatisfied":false,
"ComplaintHashCardNo":null,
"ComplaintCardBrand":null,
"ComplaintCardType":null}}
Thanks for helping.
you InfoStr value is a string, not object , so it is not valid , should be
"InfoStr": "[{\"BankEftCode\":\"1234567890\",\"TaskId\":\"12345\",\"RequestUser\":\"aaa aaa\",\"ResponseUser\":\"aaa01\",\"RequestTimestamp\":\"1234567890\",\"ResponseTimestamp\":\"134567\",\"RequestComment\":\"aaaa\",\"ResponseComment\":\"aaa\",\"InfoElements\":[{\"Key\":\"AtmCashDifferenceCurrency\",\"Value\":null,\"Type\":null},{\"Key\":\"AtmCashSurplus\",\"Value\":\"0\",\"Type\":null}]}]",

Requests for Instagram Access token

I am working on Instagram API in Django(python)
I am getting code from
'https://api.instagram.com/oauth/authorize/?client_id=%s&response_type=code&redirect_uri=%s' % (INSTAGRAM_APP_CONSUMER_KEY, redirect_uri)
but when i am exchanging code for access token code is failing
# All arguments are valid
def execute(self, code, redirect_uri, app_id, app_secret):
exchange_url = 'https://api.instagram.com/oauth/access_token'
try:
#Update : get request to post
r = requests.post(exchange_url, params={
'client_id': app_id,
'redirect_uri': redirect_uri,
'client_secret': app_secret,
'code': code,
'grant_type': 'authorization_code'
})
#print(r)
#print(json.loads(r))
print(r.json())
return r.json()
except Exception as e:
print(e)
r.json() gives simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1
Update 1 : r.json() works after request changed from get to post but error
message comming 'You must provide a client_id'
Please let me know what i am doing wrong
I think it requires data in post data, not in query params.
Try this :
your_post_data = {'client_id': '', ... }
r = requests.post('your_url', data=your_post_data)
Ref: Python Requests Docs

ruby JSON.parse fails on decimal numbers with point but without fractions

I have a json string like this :
{"weight": 56.}
I can enter this string into NodeJS interpreter and get a parsed hash as a result:
$ js
> {"Weight":56.}
{ Weight: 56 }
> {"Weight":56}
{ Weight: 56 }
as you see, NodeJS accepts both inputs with identical result
But in Ruby, for the same string I get
JSON::ParserError: ... unexpected token
until I remove '.' after the number
sample session :
irb...> s='{"Weight":56.}'
=> "{\"Weight\":56.}"
irb...> JSON.parse(s)
JSON::ParserError: 784: unexpected token at '{"Weight":56.}'
...
irb...> s='{"Weight":56}'
=> "{\"Weight\":56}"
irb...> JSON.parse(s)
=> {"Weight"=>56}
Can anything be done to Ruby JSON library to improve its conformance to JS ?
Now I have to filter these stray dec.points by regular expressions before parsing them as JSON

Escape a hypen in JSON response from Mule

I am using Anypoint Studio 6.1 and Mule 3.8.1 and have the following JSON response from a Mule workflow:
{
"Description": "Top 10 games:
- Mario Kart
- Legend of Zelda"
}
This fails validation with the following error:
Error: Parse error on line 2:
{ "Description": "Top 10 games: - M
-----------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
I have tried escaping the special characters put it still does not work. How can I change the response to pass JSON v4 validation. The JSON validator I have been using is http://jsonlint.com/
Thanks
The root cause of the issue is carriage return in the JSON response. The valid JSON should be as below
{
"Description": "Top 10 games:\r\n- Mario Kart\r\n- Legend of Zelda"
}
Please provide more details on where you are receiving this description. is it from XML or any other source. Also it will be helpful if you post your DWL code as well.

Ruby on sinatra, JSON::parserError issue and 757: unexpected token

I use rest API on Ruby with sinatra.
I got payment information from IAMPORT,,,
def get_authrestapi()
#key = IMP_KEY
#secret = IMP_SECRET
response = RestClient.post 'https://api.iamport.kr/users/getToken', {'imp_key' => #key, 'imp_secret' => #secret}, :accept => :json
json = JSON.parse(response.to_json, symbolize_names: true)
return json['response']['access_token']
end
but, I got error message... like below
JSON::ParserError at /payments 757: unexpected token at '"{\"code\":0,\"message\":null,\"response\":{\"access_token\":\"9898....", "..."}}"'
How can I solve this problem?? I think,, there is problem that variable 'json' is not HASH..
Thanks.
Don't convert the response to json. It's already json.
Replace the following line:
json = JSON.parse(response.to_json, symbolize_names: true)
with:
json = JSON.parse(response, symbolize_names: true)