Invalid JSON - Cannot see why - json

The following JSON string comes back as invalid in several formatter tests. I cannot figure out for the life of me what is wrong!
{
"draw": 122,
"recordsTotal": 1496,
"recordsFiltered": 1496,
"data": [["11315","1403","John Doe","Parking Pass","-","Hyundai Sonata - Grey ABC 123 ","09-01-2016 2:00 AM","09-01-2016 7:00 AM","-"]]
}
https://jsonformatter.org/ is saying:
Parse error on line 5: ...,"Parking Pass","-","Hyundai Sonata - Gr
-----------------------^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
https://jsonformatter.curiousconcept.com/ says:
Error:Invalid characters found.[Code 18, Structure 28]
and highlights the line "Hyundai Sonata - Grey ABC 123 ",
What the heck am I missing? I dont see any invalid characters anywhere. If I paste it into Notepad++ its not showing anything but "CRLF" on the line breaks.

After checking, it turns out that the value, which was being returned from a database, had a tab in it. I created a function to strip out any non ASCII chars and its working fine now

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}]}]",

Unable to parse a valid Json from Arabic text

This appears to be valid Json but Json parsers throw an exception on address text. Can we not have arabic values as Json values?
{
"deliveryTime":"12:34:00",
"deliveryDate":"07-09-2017",
"paymentType":1,
"deliveryMethod":1,
"address":{
"text":"\"7774 جبل الجزيره، طويق"\, "\الرياض \13791 3836، السعودية\"",
"geo":{
"latitude":24.580577,
"longitude":46.518820
},
"noteToDriver":"Near bank",
"country":"Saudi Arabia"
}
}
https://jsonlint.com/ throws an exception but I couldn't figure out the issue. It has double quotes properly escaped, the entire address value is quoted. I think the problem is due to the right to left nature of the language that resulted in the error.
Error: Parse error on line 7:
...4 جبل الجزيره، طويق"\, "\الرياض \13791
-----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'undefined'

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.

Cant validate JSON when using different language. Error invalid characters found

First time im trying to create a JSON file,
Im trying to create a JSON file with different language other than English , but when i try to validate, it show Error Invalid characters found.
i tried this
{
"data": [
{
"id": "1",
"title": "Oru Velli Thaaram Vaana Veedhiyil",
"lyrics": "ഒരു വെള്ളിത്താരം വനവീഥിയിൽ തെളിയവേ
കുളിരീറൻ കാറ്റും കുഞ്ഞുതരാട്ട് മൂളവേ
ഇരുളിനലകൾ മൂടും ധരയിതിലൊരു ദീപം
കദനഭാരമെല്ലാം നീക്കിടുന്ന സ്നേഹം
പിറന്നു മണ്ണിലുഷസ്സിൻ ശോഭ പോലെ
(ഒരു വെള്ളിത്താരം…
മരുഭൂവിൽ അലയുമ്പോൾ ആ താരം മുൻപേ
മറയാതെ രാജക്കൾക്കതുമാർഗമായി
മരുഭൂവിൽ അലയുമ്പോൾ ആ താരം മുൻപേ
മറയാതെ രാജക്കൾക്കതുമാർഗമായി
പുൽക്കൂടും തേടിത്തേടി ബെത്ലഹേമിലവരണയുമ്പോൾ
ഗീതങ്ങൾ പാടിപ്പാടി വാനദൂതരും അണയുന്നൂ
തിരുസുതനെ കാണുംനേരം പാടുന്നു ഗ്ലോറിയ …
(ഒരു വെള്ളിത്താരം…
ശാരോനിൻ താഴ്വാരം തഴുകുന്ന കാറ്റെ
വരുമോ എൻ നാഥൻറെ അരികിൽ നീ മെല്ലെ
ശാരോനിൻ താഴ്വാരം തഴുകുന്ന കാറ്റെ
വരുമോ എൻ നാഥൻറെ അരികിൽ നീ മെല്ലെ
തഴുകൂ നിൻ വിരലാൽ നെറുകിൽ സ്നേഹനാഥനെ ആലോലം
പാടൂ നൽ ശ്രുതിയാൽ കാതിൽ സാന്ദ്രമാനന്ദ സംഗീതം
ഈ രാവിൽ പാരാകെ പാടുന്നു ഗ്ലോറിയ
(ഒരു വെള്ളിത്താരം…",
},
{
"id": "2",
"title": "Pukootil Vannu Jaathanayi",
"lyrics": "പുൽക്കൂട്ടിൽ വന്നു ജാതനായി
നക്ഷത്രം ഇന്ന് മിന്നി നിന്നു
ക്രിസ്മസ് രാവിൻറെ ഗാനമായി
വിണ്ണിൽ ആനന്ദമേളമായി താരകം ദീപമായ്
കൺകളിൽ തിളങ്ങി നിന്നു (2 )
ദൂതരാ വീണകൾ മീട്ടിടുന്നിതാ
ലോകരാ കീർത്തനം കേട്ടിടുന്നിതാ
ദേവദാരു പൂത്തു പാതിരാവു പെയ്തു
മഞ്ഞുതുള്ളി വീണവീഥി മിന്നിടുന്നു
( പുൽക്കൂട്ടിൽ)
വിദ്വരോ കാഴ്ചകൾ നല്കിടുന്നിതാ
വിന്നതിൽ നോക്കി സംപ്രീതരായിതാ
കീറ്റുശീല തന്നിൽ ദിവ്യശോഭ കണ്ടു
ആട്ടിടയരെത്തി ആർത്തു പാടിടുന്നു
( പുൽക്കൂട്ടിൽ)",
}
]
}
Error shows as INVALID JSON , Invalid characters found.
please help me to resolve this problem .
Problem Coming from
"lyrics": "ഒരു വെള്ളിത്താരം വനവീഥിയിൽ തെളിയവേ
Error Type
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
Reason
Line breaks inside your string . Encode with \n .A string is a sequence of zero or more Unicode characters .

malformed JSON from Google directions API when calling from R

This might be a duplicate- but I couldn't find something to solve this problem.
I'm using httpGET() to call the google directions API.
Packages:
require(RCurl)
require(rjson)
require(gooJSON)
the code is:
url = "http://maps.googleapis.com/maps/api/directions/json?origin=12.9673293,77.7173975&destination=12.9373613,77.700985&waypoints=optimize:true|12.9723379,77.7117611|12.9922162,77.715895|12.9629354,77.7122996&sensor=false"
routeJSON = httpGET(url= url)
routeList = fromJSON(routeJSON)
I get:
Error in fromJSON(routeJSON) :
unexpected escaped character '\]' at pos 18
I wrote the JSON to a file and copied it to jsoneditoronline.com. I got:
Error: Parse error on line 51:
... "points" : "qscnA_djyMj#kAT[\]\
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
validated by jsonlint
But it works when I put the URL into the browser and copy the output to jsoneditoronline.
Any idea why it is happening and/or how to circumvent it?
EDIT: I tried gooJSON, but it seems it does not support the maps API V3.
> goomap(url)
$Status
$Status$code
[1] 610
$Status$request
[1] "geocode"
$Status$error_message
[1] "The Geocoding API v2 has been turned down on September 9th, 2013. The Geocoding API v3 should be used now. Learn more at https://developers.google.com/maps/documentation/geocoding/"
The following works fine for me:
require(rjson)
url = "http://maps.googleapis.com/maps/api/directions/json?origin=12.9673293,77.7173975&destination=12.9373613,77.700985&waypoints=optimize:true|12.9723379,77.7117611|12.9922162,77.715895|12.9629354,77.7122996&sensor=false"
fromJSON(file=url)
However, if there is invalid json data, one can call
fromJSON(url, unexpected.escape="keep")
to to treat the escaped character as normal character (e.g. \] becomes ])