JCastillo
JCastillo

Reputation: 336

JSON Validation - Invalid character found

When I hit the API its response has a special/weird character that is causing the JSON response to fail validation. Even when I try to escape the character JSON validator throw an error Escaped unescaped character. Now I'm trying to figure out if the problem comes from the backend or a Postman problem. Has anyone come across this problem where Postman return your JSON output with an invalid character that cannot be escaped?

{
    "page": 0,
    "totalRecords": 1,
    "totalPages": 1,
    "offset": 0,
    "status": "success",
    "entityList": [
        {
            "subjectcode": "HS   222",
            "coursenumber": "HS   222",
            "name": "Advanced First Aid",
            "departments": "HRHP",
            "description": "Advanced First Aid",
            "status": "A",
            "attributes": "",
            "lastoffered": "",
            "schedcode": "",
            "sectionstatus": "",
            "mincredithrs": "3.0",
            "maxcredithrs": "3.0",
            "coursenotes":"First Aid is the immediate care given to a person who has been injured or who suddenly becomes ill. It includes self-help and home care if more advanced medical assistance is not needed or is delayed. In Advanced First Aid, the student is awarded one credit for having displayed competence in both CPR and First Aid.&nbsp; The only certifications recognized are those of the American Heart Association.&nbsp; These courses do NOT need to be taken on this campus.&nbsp; However, they are offered on-line and through the University Ticket Office (http:/byui.universitytickets.com).&nbsp; For the on-line course, go to <a href=\"http://www.onlineaha.org/index.cfm?fuseaction=main.courseCatalog\">http://www.onlineaha.org/index.cfm?fuseaction=main.courseCatalog</a> and click on <a name=\"90-1401\">Heartsaver<sup></sup> First Aid CPR AED Online Part 1</a>&nbsp;under &quot;Workplace Training.&quot;&nbsp; Skills tests will need to be arranged after completing on-line portion of the course.&nbsp; To successfully complete the course, each qualifying student will show his/her curent American Heart Association's First Aid and CPR Certification cards.",
            "id": "HS   222 UG12"
        }
    ]
}

The invalid character is found in "coursenotes" value: enter image description here

Upvotes: 0

Views: 2119

Answers (1)

0stone0
0stone0

Reputation: 43972

If we copy paste your json into a hidden-chars-shower like this one we can identify the weird char as an:

Substitute character

(U+001A)


In computer data, a substitute character (␚) is a control character that is used to pad transmitted data in order to send it in blocks of fixed size, or to stand in place of a character that is recognized to be invalid, erroneous or unrepresentable on a given device


enter image description here


Consider replacing it with a 'normal' char before parsing as JSON


Some related posts:

Upvotes: 1

Related Questions