0

i have json file as below and tried to convert to python dictionary but getting error

{
  "response": {
    "dev_log": {
      "data": [
        {
          "id": "1",
          "timestamp": "2020-01-16 10:11:12",
          "email": "johnd@gmail.com"
        },
        {
          "id": "2",
          "timestamp": "2020-02-27 15:33:34",
          "email": "zack@gmail.com"
        },
        {
          "id": "3",
          "timestamp": "2020-02-27 15:34:07",
          "email": "edy@yahoo.com"
        }
      ],
      "total_dev_log": "1423"
    },
    "client_log": {
      "data": [
        {
          "customer_city": "LONDON",
          "customer_login": "AAAAAAAAAAAAAA",
          "customer_state": "MC",
          "details": "aaaaaaaaaaa-bbbbbbbbbbbbbbb-cccccccccccccc ",
          "log_number": "1",
          "dept": "Sales",
          "staff_id": "S123",
          "staff_name": "EricY",
          "timestamp": "2020-02-27 15:57:24"
        },
        {
          "customer_city": "SINGAPORE",
          "customer_login": "BBBBBBBBBBBBB",
          "customer_state": "XX",
          "details": "ddddddddd-eeeeeeeeeeee-ffffffffffff ",
          "log_number": "1",
          "dept": "Eng",
          "staff_id": "S456",
          "staff_name": "YongG",
          "timestamp": "2020-02-27 15:57:24"
        }
      ],
      "total_hero_query": "13"
    },
    "response_time": "0.723494",
    "transaction_id": "909122",
    "transaction_status": "OK",
    "transaction_time": "Fri Feb 28 15:27:51 2020"
  }
}

I'm able to view as a valid json via http://jsonviewer.stack.hu. I believed its a valid json string format.

Normallay I just use code below to read json file and convert it to dict but I'm getting error.

with open('datfile.json', 'r') as f:
   datDict = json.load(f)

Error

Traceback (most recent call last):
  File "strg2dict.py", line 4, in <module>
    json_dict = json.load(JSON)
  File "/usr/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 22 column 5 (char 466)

I have check from others solution but still not able to find the solution. Please advise further. Thank you

@@@@@@@@@@@@@@@@@@@@@@@@@ Got comma "total_dev_log": "1423",

===> remove comma "total_dev_log": "1423"

RESOLVED> Thank you

chenoi
  • 575
  • 3
  • 8
  • 30

1 Answers1

2

Your json file includes a trailing comma on line 21:

"total_dev_log": "1423",
                       ^ 

The JSON specification does not allow for trailing commas. Simply delete this comma to correct the error.

Brian61354270
  • 8,690
  • 4
  • 21
  • 43
  • Thank you sir. I have corrected the line. and ok. Thank you – chenoi Mar 12 '20 at 02:54
  • @chenoi Glad to here that this solved your problem. If my answer suffices, consider marking it as accepted so that this question can be removed from the unanswered question pool. See [this help center topic](https://stackoverflow.com/help/someone-answers) for more info. – Brian61354270 Mar 12 '20 at 02:57