Search code examples
javascriptjqueryjsonzepto

Parse JSON returns unexpected identifier error


I am trying to parse the following JSON string that is being returned to me but am getting an unexpected identifier error in the console.

"{"title":"MyApp Companion","push_hash":"ff06b5b775e45409f9ab470b64d672d0","t":"mr","alert":"Ryjjgv","n":"Foo Bar","action":"open the app at specific location","pid":"7V8meRCJaj","badge":"Increment"}" 

I am using zepto but the method $.parseJSON() throws the error.


Solution

  • remove your first and last " or replace with '

    "{
        "title": "MyApp Companion",
        "push_hash": "ff06b5b775e45409f9ab470b64d672d0",
        "t": "mr",
        "alert": "Ryjjgv",
        "n": "Foo Bar",
        "action": "open the app at specific location",
        "pid": "7V8meRCJaj",
        "badge": "Increment"
    }"
    

    to

     '{
            "title": "MyApp Companion",
            "push_hash": "ff06b5b775e45409f9ab470b64d672d0",
            "t": "mr",
            "alert": "Ryjjgv",
            "n": "Foo Bar",
            "action": "open the app at specific location",
            "pid": "7V8meRCJaj",
            "badge": "Increment"
        }'
    

    and there is on online TOOL jsonlint.com , to validate your JSON