Mahbub Rahman
Mahbub Rahman

Reputation: 1343

JSON: Parsing JSON string with json.loads gets error: Expecting , delimiter:

The JSON string below get error: ValueError: Expecting , delimiter: line 1 column ....

{"EndUsrIpAdr":"x.x.x.x","EndUsrBrwsrAgnt":"Mozilla/5.0 (Linux; Android 5.1; Bush Spira E2X 5" Smartphone Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36","ReqOrg":"xxx.com"}

Modifying E2X 5" to E2X 5 solves the error.

How I can remove this " from : E2X 5" , because if I use replace, I am afraid it will remove all "" from the JSON string.

Upvotes: 0

Views: 680

Answers (1)

sudo
sudo

Reputation: 943

Its an invalid JSON, you can validate your json here https://jsonlint.com

You can use \" delimiter to add " or any other escape character

Here is python sample code to parse son

import json
with open("jsonFileName.json") as _fp:
    try:
        _json_data = json.load(_fp)
        # _json_data is a python dict, if everything went correct
    except:
        # error in parsing son
        pass

Upvotes: 1

Related Questions