skip to Main Content

I have a JSON string here. In Python, whenever I json.loads(string), I get json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 21 (char 20). However, I am completely lost on why it is an improperly formatted JSON. I have tried adding r infront of the string but with no avail.

JSON String:

string = '{"alarm_flood": "[{"Date_Time": "01-12-2009 12:18:42", "flood_status": "1", "FloodIndex": "0", "Plant_Area": "AREA 1"}, {"Date_Time": "01-12-2009 12:18:42", "flood_status": "0", "FloodIndex": "0", "Plant_Area": "AREA 1"}]", "flood_status": "[{"Date_Time": "01-12-2009 12:18:42", "flood_status": "1", "FloodIndex": "0", "Plant_Area": "AREA 1"}, {"Date_Time": "01-12-2009 12:18:42", "flood_status": "0", "FloodIndex": "0", "Plant_Area": "AREA 1"}]"}'

Can someone point me to the right direction?

2

Answers


  1. You had some extra quotation marks. Here is the corrected version:

    string = '{"alarm_flood": [{"Date_Time": "01-12-2009 12:18:42", "flood_status": "1", "FloodIndex": "0", "Plant_Area": "AREA 1"}, {"Date_Time": "01-12-2009 12:18:42", "flood_status": "0", "FloodIndex": "0", "Plant_Area": "AREA 1"}], "flood_status": [{"Date_Time": "01-12-2009 12:18:42", "flood_status": "1", "FloodIndex": "0", "Plant_Area": "AREA 1"}, {"Date_Time": "01-12-2009 12:18:42", "flood_status": "0", "FloodIndex": "0", "Plant_Area": "AREA 1"}]}'
    
    Login or Signup to reply.
  2. you have some extra double quotes, you can remove them using replace

    string = string.replace('"[', '[').replace(']"', ']');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search